Adding Images to Tab in Android -
i have developed simple android application in have implemented tabs using fragments... unable display images tabs.. have attached source code below.. please let me know error...
my activity class tabdemofragmentactivity.java
public class tabdemofragmentactivity extends fragmentactivity { /** * instance variable of type {@link fragmenttabhost} */ private fragmenttabhost fragmenttabhost; /** * call method, gets invoked * when instance of class created. * * <p> * method used set tab host , * add tab host fragments screen, * acts ui. * </p> */ @override protected void oncreate(bundle bundle) { super.oncreate(bundle); setcontentview(r.layout.activity_fragment_main); fragmenttabhost = (fragmenttabhost) findviewbyid(android.r.id.tabhost); fragmenttabhost.setup(this, getsupportfragmentmanager(), r.id.realtabcontent); fragmenttabhost.addtab(fragmenttabhost.newtabspec("dropcall details").setindicator("dropcall details", getresources().getdrawable(r.drawable.drop_call_image)).setcontent(intent), qosdropcalldetailsfragment.class, null); fragmenttabhost.addtab(fragmenttabhost.newtabspec("network details").setindicator("network details", getresources().getdrawable(r.drawable.network_details)), qosnetworkdetailsfragment.class, null); } }
my xml file
<android.support.v4.app.fragmenttabhost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="match_parent" > <linearlayout android:layout_width="fill_parent" android:layout_height="match_parent" android:orientation="vertical" > <tabwidget android:id="@android:id/tabs" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_weight="0" android:orientation="horizontal" /> <framelayout android:id="@+id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="50" /> <framelayout android:id="@+id/realtabcontent" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" /> </linearlayout> </android.support.v4.app.fragmenttabhost>
image not getting displayed here.. please let me know how display images in tabs.. thanks
i realize old question hoping might land on page. first, let me point out fragmenttabhost deprecated approach adding tabs in app. google wants move actiontabbar add tabs.
i had done similar implementation yours , don't see difference. however, 2 things can point out code first, need make sure copy image 3 drawable folders. second, remove framelayout(tabcontent) have in xml because had 1 framelayout , don't see using other 1 in activity class.
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.app.fragmenttabhost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" > <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <tabwidget android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0" android:orientation="horizontal" /> <framelayout android:id="@+id/tabframelayout" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> </linearlayout> </android.support.v4.app.fragmenttabhost>
here snippet of activity class:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_fragment); mtabhost = (fragmenttabhost) findviewbyid(r.id.tabhost); mtabhost.setup(this, getsupportfragmentmanager(), r.id.tabframelayout); mtabhost.addtab( mtabhost.newtabspec("tab1").setindicator("tab 1", getresources().getdrawable(r.drawable.user_card)), tabactivity.listfragment.class, null); mtabhost.addtab( mtabhost.newtabspec("tab2").setindicator("tab 2", getresources().getdrawable(r.drawable.menu)), tabactivity.listfragments.class, null); }
Comments
Post a Comment