android - why i can't see the Tab of the tabHost? -
i did same code on googles example - , want see tab can click on them , switch between tabs.
i can't see tabs ..
the code:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity"> <tabhost android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparenttop="true" android:layout_centerhorizontal="true"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <tabwidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" /> <framelayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:id="@+id/action" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@android:color/black"> <textview android:layout_width="match_parent" android:layout_height="match_parent" android:text="this tab 1" /> </linearlayout> <linearlayout android:id="@+id/memo" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@android:color/holo_red_dark"> <textview android:layout_width="match_parent" android:layout_height="match_parent" android:text="this tab 2" /> </linearlayout> <linearlayout android:id="@+id/settings" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@android:color/holo_blue_light"> <textview android:layout_width="match_parent" android:layout_height="match_parent" android:text="this tab 3" /> </linearlayout> </framelayout> </linearlayout> </tabhost> </linearlayout>
try this.
add
tabhost
id in xml codeandroid:id="@+id/tabhost"
add
tabhost
initialization information inoncreate()
method@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_tab_host); tabhost mtabhost = (tabhost) findviewbyid(r.id.tabhost); mtabhost.setup(); mtabhost.addtab(mtabhost.newtabspec("action").setindicator("title1", null).setcontent(r.id.action)); mtabhost.addtab(mtabhost.newtabspec("memo").setindicator("title2", null).setcontent(r.id.memo)); mtabhost.addtab(mtabhost.newtabspec("settings").setindicator("title3", null).setcontent(r.id.settings)); }
Comments
Post a Comment