添加tab标签

系统管理员 2022-08-06 09:09 257阅读 0赞

1.xml

  1. <TabHost
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:layout_below="@id/show">
  5. <LinearLayout android:id="@+id/tab1"
  6. android:orientation="vertical"
  7. android:layout_width="fill_parent"
  8. android:layout_height="fill_parent">
  9. <TextView
  10. android:id="@+id/text_tab1"
  11. android:layout_width="fill_parent"
  12. android:layout_height="fill_parent"
  13. android:text="favorite"
  14. />
  15. </LinearLayout>
  16. <LinearLayout android:id="@+id/tab2"
  17. android:orientation="vertical"
  18. android:layout_width="fill_parent"
  19. android:layout_height="fill_parent">
  20. <TextView
  21. android:id="@+id/text_tab2"
  22. android:layout_width="fill_parent"
  23. android:layout_height="fill_parent"
  24. android:text="contacts"
  25. />
  26. </LinearLayout>
  27. </TabHost>

2.代码

  1. public class PeopleActivity extends TabActivity {
  2. @Override
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. getWindow().requestFeature(Window.FEATURE_NO_TITLE);
  6. //setContentView(R.layout.activity_main);
  7. TabHost tabHost = getTabHost();
  8. LayoutInflater.from(this).inflate(R.layout.activity_main,
  9. tabHost.getTabContentView(),true);
  10. tabHost.addTab(tabHost.newTabSpec("tab1")
  11. .setIndicator("contacts")
  12. .setContent(R.id.tab1));
  13. tabHost.addTab(tabHost.newTabSpec("tab2")
  14. .setIndicator("chat")
  15. .setContent(R.id.tab2));
  16. }

发表评论

表情:
评论列表 (有 0 条评论,257人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Navigation-Tabs标签

    Tabs 标签页:分隔内容上有关联但属于不同类别的数据集合。 1、基本使用 Tabs 组件提供了选项卡功能,默认选中第一个标签页,你也可以通过 value(v-model