资源预览内容
第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
第9页 / 共9页
亲,该文档总共9页全部预览完了,如果喜欢就下载吧!
资源描述
现在很多 android 的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用 TabHost 组件来自定义一个底部的导航栏的功能。我们先看下该 demo 实例的框架图:其中各个类的作用以及资源文件就不详细解释了,还有资源图片(在该 Demo 中借用了其它应用程序的资源图片)也不提供了,大家可以自行更换自己需要的资源图片。直接上各个布局文件或各个类的代码:1 res/layout 目录下的 maintabs.xml 源码:html view plaincopy1. 2. 4. 5. 6. 7. 10. 11. 12. 13. 14. 15. 16. 17. 2 res/drawable 下的 home_btn_bg.xml 源码:html view plaincopy1. 2. 4. 5. 6. 7. 8. 3 res/values 下的源码:dimens.xml 源码html view plaincopy1. 2. 3. 4. 10.0sp 5. 5.0dip 6. 2.0dip 7. 30.0sp 8. 100.0dip 9. 48.0dip 10. 20.0dip 11. 19.0dip 12. 10.0dip 13. 20.0dip 14. 10.0dip 15. 35.0dip 16. 74.0dip 17. 70.0dip 18. 13.299988dip 19. 20.0dip 20. 0.0dip 21. 20.0sp 22. 10.0dip 23. 50.0dip 24. 25. drawables.xml 源码:html view plaincopy1. 2. 3. 4. #fff4f4f4 5. #fffff4db 6. #ff000000 7. #00000000 8. android:color/transparent 9. #99000000 10. #fff4f4f4 11. #ff272727 12. #ff333333 13. 14. ids.xml 源码:html view plaincopy1. 2. 3. 4. false 5. false 6. false 7. false 8. false 9. false 10. 11. strings.xml 源码:html view plaincopy1. 2. 3. Hello World, MainTabActivity! 4. TabDemo 5. 消息 6. 首页 7. 更多 8. 时间 9. 好友 10. styles.xml 源码:html view plaincopy1. 2. 3. 4. 5. dimen/bottom_tab_font_size 6. #ffffffff 7. marquee 8. center_horizontal 9. drawable/home_btn_bg 10. dimen/bottom_tab_padding_up 11. 2.0dip 12. fill_parent 13. wrap_content 14. 2.0dip 15. null 16. true 17. dimen/bottom_tab_padding_drawable 18. 1.0 19. 20. 21. 4 src/com.andyidea.tabdemo 包下面各个 UI 界面类源码:MainTabActivity.java 源码:html view plaincopy1.package com.andyidea.tabdemo; 2. 3.import android.app.TabActivity; 4.import android.content.Intent; 5.import android.os.Bundle; 6.import android.view.Window; 7.import android.widget.CompoundButton; 8.import android.widget.RadioButton; 9.import android.widget.CompoundButton.OnCheckedChangeListener; 10. import android.widget.TabHost; 11. 12. public class MainTabActivity extends TabActivity implements OnCheckedChangeListener 13. 14. private TabHost mTabHost; 15. private Intent mAIntent; 16. private Intent mBIntent; 17. private Intent mCIntent; 18. private Intent mDIntent; 19. private Intent mEIntent; 20. 21. /* Called when the activity is first created. */ 22. Override 23. public void onCreate(Bundle savedInstanceState) 24. super.onCreate(savedInstanceState); 25. requestWindowFeature(Window.FEATURE_NO_TITLE); 26. setContentView(R.layout.maintabs); 27. 28. this.mAIntent = new Intent(this,AActivity.class); 29. this.mBIntent = new Intent(this,BActivity.class); 30. this.mCIntent = new Intent(this,CActivity.class); 31. this.mDIntent = new Intent(this,DActivity.class); 32. this.mEIntent = new Intent(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. Override 49. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 50. if(isChecked) 51. switch (buttonView.getId() 52. case R.id.radio_button0: 53. this.mTabHost.setCurrentTabByTag(“A_TAB“); 54. break; 55. case R.id.radio_button1: 56. this.mTabHost.setCurrentTabByTag(“B_TAB“); 57. break; 58. case R.id.radio_button2: 59. this.mTabHost.setCurrentTabByTag(“C_TAB“); 60. break; 61. case R.id.radio_button3: 62. this.mTabHost.setCurrentTabByTag(“D_TAB“); 63. break; 64. case R.id.radio_button4: 65. this.mTabHost.setCurrentTabByTag(“MORE_TAB“); 66. break; 67. 68. 69. 70. 71. 72. private void setupIntent() 73. this.mTabHost = getTabHost(); 74. TabHost localTabHost = this.mTabHost; 75.
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号