当前位置:首页 > Android TabHost用法
红色部分是本文要实现的目标。
二、实现 maintabs.xml [html] view plaincopyprint?
1.
2. ndroid:layout_height=\ 3. xmlns:android=\> 4. t\ android:layout_height=\> 5. \ android:layout_height=\ android:layout_weight=\ /> 6. d:layout_width=\ android:layout_height=\ android:layout_weight=\ /> 7. ttom\ android:orientation=\ android:id=\ android:background=\ android:layout_width=\ android:layout_height=\> 8. ue\ android:id=\ android:layout_marginTop=\ android:drawableTop=\ style=\ /> 9. op=\ android:text=\ android:drawableTop=\able/icon_2_n\ style=\ /> 10. nTop=\ android:text=\ android:drawableTop=\drawable/icon_3_n\ style=\ /> 11. nTop=\ android:text=\ android:drawableTop=\drawable/icon_4_n\ style=\ /> 12. nTop=\ android:text=\ android:drawableTop=\e/icon_5_n\ style=\ /> 13.
styles.xml
[html] view plaincopyprint?
1.
home_btn_bg.xml
[html] view plaincopyprint?
1. 2. xmlns:android=\> 3. d:state_pressed=\ android:drawable=\ /> 4. d:drawable=\ /> 5. id:drawable=\ /> 6.
代码说明:
1. 需要注意的是他这里把TabWidget的Visibility设置成了gone!也就是默认难看的风格不见了:钮.
,取而代之的是5个带风格的单选按
2. 注意为单选按钮设置的style,其中最重要的是为其background设置了home_btn_bg.xml,也就是自定义了选中效果。 Java文件 [java] view plaincopyprint?
1. public class MainTabActivity extends TabActivity implements 2. OnCheckedChangeListener { 3.
4. private TabHost mHost; 5. private Intent mMBlogIntent; 6. private Intent mMoreIntent; 7. private Intent mInfoIntent; 8. private Intent mSearchIntent; 9. private Intent mUserInfoIntent; 10.
11. @Override
12. protected void onCreate(Bundle savedInstanceState) { 13. super.onCreate(savedInstanceState);
14. requestWindowFeature(Window.FEATURE_NO_TITLE); 15. setContentView(R.layout.maintabs); 16.
17. // ~~~~~~~~~~~~ 初始化
18. this.mMBlogIntent = new Intent(this, HomeListActivity.class); 19. this.mSearchIntent = new Intent(this, SearchSquareActivity.class); 20. this.mInfoIntent = new Intent(this, MessageGroup.class); 21. this.mUserInfoIntent = new Intent(this, MyInfoActivity.class); 22. this.mMoreIntent = new Intent(this, MoreItemsActivity.class); 23.
24. initRadios(); 25.
26. setupIntent(); 27. } 28. 29. /**
共分享92篇相关文档