网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Android中如何实现选项卡功能-创新互联

这篇文章主要介绍“Android中如何实现选项卡功能”,在日常操作中,相信很多人在Android中如何实现选项卡功能问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Android中如何实现选项卡功能”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

为南宁等地区用户提供了全套网页设计制作服务,及南宁网站建设行业解决方案。主营业务为网站设计制作、做网站、南宁网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

首先创建Android工程命名自己的Activity为HelloTabWidget

在main.xml或者自己定义的*.xml文件中创建一个TabHost,需要两个元素TabWidget和FrameLayout 通常会把这两个元素放到LinearLayout中。FrameLayout作为改变内容content用的。
注意:TabWidget和FrameLayout 有不同的ID命名空间android:id="@android:id/idnames",这个是必须的因此TabHost才能自动找到它,Activity需要继承TabActivity。

Android选项卡Xml代码

  1. < ?xml version="1.0" encoding="utf-8"?> 

  2. < TabHost xmlns:android=
    "http://schemas.android.com/apk/res/android" 

  3. android:id="@android:id/tabhost" 

  4. android:layout_width="fill_parent" 

  5. android:layout_height="fill_parent"> 

  6. < LinearLayout 

  7. android:orientation="vertical" 

  8. android:layout_width="fill_parent" 

  9. android:layout_height="fill_parent"> 

  10. < TabWidget 

  11. android:id="@android:id/tabs" 

  12. android:layout_width="fill_parent" 

  13. android:layout_height="wrap_content" /> 

  14. < FrameLayout 

  15. android:id="@android:id/tabcontent" 

  16. android:layout_width="fill_parent" 

  17. android:layout_height="fill_parent"> 

  18. < TextView 

  19. android:id="@+id/textview1" 

  20. android:layout_width="fill_parent" 

  21. android:layout_height="fill_parent" 

  22. android:text="this is a tab" /> 

  23. < TextView 

  24. android:id="@+id/textview2" 

  25. android:layout_width="fill_parent" 

  26. android:layout_height="fill_parent" 

  27. android:text="this is another tab" /> 

  28. < TextView 

  29. android:id="@+id/textview3" 

  30. android:layout_width="fill_parent" 

  31. android:layout_height="fill_parent" 

  32. android:text="this is a third tab" /> 

  33. < /FrameLayout> 

  34. < /LinearLayout> 

  35. < /TabHost> 

  36. < ?xml version="1.0" encoding="utf-8"?>

  37. < TabHost xmlns:android=
    "http://schemas.android.com/apk/res/android"

  38. android:id="@android:id/tabhost"

  39. android:layout_width="fill_parent"

  40. android:layout_height="fill_parent">

  41. < LinearLayout

  42. android:orientation="vertical"

  43. android:layout_width="fill_parent"

  44. android:layout_height="fill_parent">

  45. < TabWidget

  46. android:id="@android:id/tabs"

  47. android:layout_width="fill_parent"

  48. android:layout_height="wrap_content" />

  49. < FrameLayout

  50. android:id="@android:id/tabcontent"

  51. android:layout_width="fill_parent"

  52. android:layout_height="fill_parent">

  53. < TextView 

  54. android:id="@+id/textview1"

  55. android:layout_width="fill_parent"

  56. android:layout_height="fill_parent" 

  57. android:text="this is a tab" />

  58. < TextView 

  59. android:id="@+id/textview2"

  60. android:layout_width="fill_parent"

  61. android:layout_height="fill_parent" 

  62. android:text="this is another tab" />

  63. < TextView 

  64. android:id="@+id/textview3"

  65. android:layout_width="fill_parent"

  66. android:layout_height="fill_parent" 

  67. android:text="this is a third tab" />

  68. < /FrameLayout>

  69. < /LinearLayout>

  70. < /TabHost>

Activity需要继承TabActivity

Android选项卡Java代码

public class HelloTabWidget extends TabActivity   public class HelloTabWidget extends TabActivity

Android选项卡Java代码

  1. public void onCreate(Bundle savedInstanceState) { 

  2. super.onCreate(savedInstanceState); 

  3. setContentView(R.layout.main); 

  4. mTabHost = getTabHost(); 

  5. mTabHost.addTab(mTabHost.newTabSpec("tab_test1").
    setIndicator("TAB 1").setContent(R.id.textview1)); 

  6. mTabHost.addTab(mTabHost.newTabSpec("tab_test2").
    setIndicator("TAB 2").setContent(R.id.textview2)); 

  7. mTabHost.addTab(mTabHost.newTabSpec("tab_test3").
    setIndicator("TAB 3").setContent(R.id.textview3)); 

  8. mTabHost.setCurrentTab(0); 

  9. }

到此,关于“Android中如何实现选项卡功能”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


分享标题:Android中如何实现选项卡功能-创新互联
分享URL:http://bjjierui.cn/article/copcgd.html

其他资讯