Android底部菜单栏demo
Android底部菜单栏demo
Android底部菜单栏很重要,我看了一下很多应用软件都是用了底部菜单栏做。我这里使用了tabhost做了一种通用的(就是可以像微信那样显示未读消息数量的,虽然之前也做过但是layout下的xml写的太臃肿,这里去掉了很多不必要的层,个人看起来还是不错的,所以贴出来方便以后使用)。
先看一下做出来之后的效果:
以后使用的时候就可以换成自己项目的图片和字体了,主框架不用变哈哈,
首先是要布局layout下xml文件 main.xml:
- <?xml version="1.0" encoding="UTF-8"?>
- <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@android:id/tabhost"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" >
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@color/bg_gray"
- android:orientation="vertical" >
- <FrameLayout
- android:id="@android:id/tabcontent"
- android:layout_width="fill_parent"
- android:layout_height="0.0dip"
- android:layout_weight="1.0" />
- <TabWidget
- android:id="@android:id/tabs"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="0.0"
- android:visibility="gone" />
- <FrameLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- <RadioGroup
- android:id="@+id/main_tab_group"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom"
- android:background="@drawable/bottom1"
- android:gravity="bottom"
- android:orientation="horizontal"
- >
- <RadioButton
- android:id="@+id/main_tab_addExam"
- style="@style/MMTabButton"
- android:layout_weight="1.0"
- android:drawableTop="@drawable/bg_checkbox_icon_menu_0"
- android:text="添加考试" />
- <RadioButton
- android:id="@+id/main_tab_myExam"
- style="@style/MMTabButton"
- android:layout_weight="1.0"
- android:checked="true"
- android:drawableTop="@drawable/bg_checkbox_icon_menu_1"
- android:text="我的考试" />
- <RadioButton
- android:id="@+id/main_tab_message"
- style="@style/MMTabButton"
- android:layout_weight="1.0"
- android:drawableTop="@drawable/bg_checkbox_icon_menu_2"
- android:text="我的通知" />
- <RadioButton
- android:id="@+id/main_tab_settings"
- style="@style/MMTabButton"
- android:layout_weight="1.0"
- android:drawableTop="@drawable/bg_checkbox_icon_menu_3"
- android:text="设置" />
- </RadioGroup>
- <TextView
- android:id="@+id/main_tab_new_message"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal|top"
- android:layout_marginLeft="60dip"
- android:layout_marginTop="1dip"
- android:background="@drawable/tips"
- android:gravity="center"
- android:text="1"
- android:textColor="#ffffff"
- android:textSize="10sp"
- android:visibility="gone" />
- </FrameLayout>
- </LinearLayout>
- </TabHost>
|
评论暂时关闭