Android应用底部导航栏实例.docx_第1页
Android应用底部导航栏实例.docx_第2页
Android应用底部导航栏实例.docx_第3页
Android应用底部导航栏实例.docx_第4页
Android应用底部导航栏实例.docx_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

现在很多android的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用TabHost组件来自定义一个底部的导航栏的功能。我们先看下该demo实例的框架图:其中各个类的作用以及资源文件就不详细解释了,还有资源图片(在该Demo中借用了其它应用程序的资源图片)也不提供了,大家可以自行更换自己需要的资源图片。直接上各个布局文件或各个类的代码:1 res/layout目录下的 maintabs.xml 源码:htmlview plaincopy1. 2. 4. 5. 6. 7. 10. 11. 12. 13. 14. 15. 16. 17. 2 res/drawable 下的 home_btn_bg.xml 源码:htmlview plaincopy1. 2. 4. 5. 6. 7. 8. 3 res/values 下的源码:dimens.xml源码htmlview plaincopy1. 2. 3. 4. 10.0sp5. 5.0dip6. 2.0dip7. 30.0sp8. 100.0dip9. 48.0dip10. 20.0dip11. 19.0dip12. 10.0dip13. 20.0dip14. 10.0dip15. 35.0dip16. 74.0dip17. 70.0dip18. 13.299988dip19. 20.0dip20. 0.0dip21. 20.0sp22. 10.0dip23. 50.0dip24. 25. drawables.xml源码:htmlview plaincopy1. 2. 3. 4. #fff4f4f45. #fffff4db6. #ff0000007. #000000008. android:color/transparent9. #9900000010. #fff4f4f411. #ff27272712. #ff33333313. 14. ids.xml源码:htmlview plaincopy1. 2. 3. 4. false5. false6. false7. false8. false9. false10. 11. strings.xml源码:htmlview plaincopy1. 2. 3. HelloWorld,MainTabActivity!4. TabDemo5. 消息6. 首页7. 更多8. 时间9. 好友10. styles.xml源码:htmlview plaincopy1. 2. 3. 4. 5. dimen/bottom_tab_font_size6. #ffffffff7. marquee8. center_horizontal9. drawable/home_btn_bg10. dimen/bottom_tab_padding_up11. 2.0dip12. fill_parent13. wrap_content14. 2.0dip15. null16. true17. dimen/bottom_tab_padding_drawable18. 1.019. 20. 21. 4 src/com.andyidea.tabdemo包下面各个UI界面类源码:MainTabActivity.java源码:htmlview plaincopy1. packagecom.andyidea.tabdemo;2. 3. importandroid.app.TabActivity;4. importandroid.content.Intent;5. importandroid.os.Bundle;6. importandroid.view.Window;7. importandroid.widget.CompoundButton;8. importandroid.widget.RadioButton;9. importandroid.widget.CompoundButton.OnCheckedChangeListener;10. importandroid.widget.TabHost;11. 12. publicclassMainTabActivityextendsTabActivityimplementsOnCheckedChangeListener13. 14. privateTabHostmTabHost;15. privateIntentmAIntent;16. privateIntentmBIntent;17. privateIntentmCIntent;18. privateIntentmDIntent;19. privateIntentmEIntent;20. 21. /*Calledwhentheactivityisfirstcreated.*/22. Override23. publicvoidonCreate(BundlesavedInstanceState)24. super.onCreate(savedInstanceState);25. requestWindowFeature(Window.FEATURE_NO_TITLE);26. setContentView(R.layout.maintabs);27. 28. this.mAIntent=newIntent(this,AActivity.class);29. this.mBIntent=newIntent(this,BActivity.class);30. this.mCIntent=newIntent(this,CActivity.class);31. this.mDIntent=newIntent(this,DActivity.class);32. this.mEIntent=newIntent(this,EActivity.class);33. 34. (RadioButton)findViewById(R.id.radio_button0)35. .setOnCheckedChangeListener(this);36. (RadioButton)findViewById(R.id.radio_button1)37. .setOnCheckedChangeListener(this);38. (RadioButton)findViewById(R.id.radio_button2)39. .setOnCheckedChangeListener(this);40. (RadioButton)findViewById(R.id.radio_button3)41. .setOnCheckedChangeListener(this);42. (RadioButton)findViewById(R.id.radio_button4)43. .setOnCheckedChangeListener(this);44. 45. setupIntent();46. 47. 48. Override49. publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked)50. if(isChecked)51. switch(buttonView.getId()52. caseR.id.radio_button0:53. this.mTabHost.setCurrentTabByTag(A_TAB);54. break;55. caseR.id.radio_button1:56. this.mTabHost.setCurrentTabByTag(B_TAB);57. break;58. caseR.id.radio_button2:59. this.mTabHost.setCurrentTabByTag(C_TAB);60. break;61. caseR.id.radio_button3:62. this.mTabHost.setCurrentTabByTag(D_TAB);63. break;64. caseR.id.radio_button4:65. this.mTabHost.setCurrentTabByTag(MORE_TAB);66. break;67. 68. 69. 70. 71. 72. privatevoidsetupIntent()73. this.mTabHost=getTabHost();74. TabHostlocalTabHost=this.mTabHost;75. 76. localTabHost.addTab(buildTabSpec(A_TAB,R.string.main_home,77. R.drawable.icon_1_n,this.mAIntent);78. 79. localTabHost.addTab(buildTabSpec(B_TAB,R.string.main_news,80. R.drawable.icon_2_n,this.mBIntent);81. 82. localTabHost.addTab(buildTabSpec(C_TAB,83. R.string.main_manage_date,R.drawable.icon_3_n,84. this.mCIntent);85. 86. localTabHost.addTab(buildTabSpec(D_TAB,R.string.main_friends,87. R.drawable.icon_4_n,this.mDIntent);88. 89. localTabHost.addTab(buildTabSpec(MORE_TAB,R.string.more,90. R.drawable.icon_5_n,this.mEIntent);91. 92. 93. 94. privateTabHost.TabSpecbuildTabSpec(Stringtag,intresLabel,intresIcon,95. finalIntentcontent)96. returnthis.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel),97. getResources().getDrawable(resIcon).setContent(content);98. 99. 其中 AActivity.java 与 BActivity.java ,CActivity.java ,DActivity.java ,EActivity.java 中的源码都一样,只是用来表示不同的界面展示,故这里只列出 AActivity.java的源码:htmlview plaincopy1. packagecom.andyidea.tabdemo;2. 3. importandroid.app.Activity;4. importandroid.os.Bundle;5. importandroid.view.Gravity;6. importandroid.widget.TextView;7. 8. publicclassAActivityextendsActivity9. 10. Override11. publicvoidonCreate(BundlesavedInstanceState)12. super.onCreate(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论