android应用底部导航栏实例

上传人:xzh****18 文档编号:35367432 上传时间:2018-03-14 格式:DOCX 页数:9 大小:61.94KB
返回 下载 相关 举报
android应用底部导航栏实例_第1页
第1页 / 共9页
android应用底部导航栏实例_第2页
第2页 / 共9页
android应用底部导航栏实例_第3页
第3页 / 共9页
android应用底部导航栏实例_第4页
第4页 / 共9页
android应用底部导航栏实例_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《android应用底部导航栏实例》由会员分享,可在线阅读,更多相关《android应用底部导航栏实例(9页珍藏版)》请在金锄头文库上搜索。

1、现在很多 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、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. 1

3、3.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.

4、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_horiz

5、ontal 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

6、.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.wi

7、dget.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. /* Call

8、ed 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. t

9、his.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(th

10、is); 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) findVie

11、wById(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.setCurrentTabByT

12、ag(“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.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > IT计算机/网络 > 多媒体应用

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号