Android底部菜单栏demo


Android底部菜单栏很重要,我看了一下很多应用软件都是用了底部菜单栏做。我这里使用了tabhost做了一种通用的(就是可以像微信那样显示未读消息数量的,虽然之前也做过但是layout下的xml写的太臃肿,这里去掉了很多不必要的层,个人看起来还是不错的,所以贴出来方便以后使用)。

先看一下做出来之后的效果:

以后使用的时候就可以换成自己项目的图片和字体了,主框架不用变哈哈,

首先是要布局layout下xml文件 main.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@android:id/tabhost"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent" >  
  6.   
  7.     <LinearLayout  
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="fill_parent"  
  10.         android:background="@color/bg_gray"  
  11.         android:orientation="vertical" >  
  12.   
  13.         <FrameLayout  
  14.             android:id="@android:id/tabcontent"  
  15.             android:layout_width="fill_parent"  
  16.             android:layout_height="0.0dip"  
  17.             android:layout_weight="1.0" />  
  18.   
  19.         <TabWidget  
  20.             android:id="@android:id/tabs"  
  21.             android:layout_width="fill_parent"  
  22.             android:layout_height="wrap_content"  
  23.             android:layout_weight="0.0"  
  24.             android:visibility="gone" />  
  25.   
  26.         <FrameLayout  
  27.             android:layout_width="fill_parent"  
  28.             android:layout_height="wrap_content" >  
  29.   
  30.             <RadioGroup  
  31.                 android:id="@+id/main_tab_group"  
  32.                 android:layout_width="fill_parent"  
  33.                 android:layout_height="wrap_content"  
  34.                 android:layout_gravity="bottom"  
  35.                 android:background="@drawable/bottom1"  
  36.                 android:gravity="bottom"  
  37.                 android:orientation="horizontal"  
  38.                  >  
  39.   
  40.                 <RadioButton  
  41.                     android:id="@+id/main_tab_addExam"  
  42.                     style="@style/MMTabButton"  
  43.                     android:layout_weight="1.0"      
  44.                     android:drawableTop="@drawable/bg_checkbox_icon_menu_0"  
  45.                     android:text="添加考试" />  
  46.   
  47.                 <RadioButton  
  48.                     android:id="@+id/main_tab_myExam"  
  49.                     style="@style/MMTabButton"  
  50.                     android:layout_weight="1.0"  
  51.                     android:checked="true"  
  52.                     android:drawableTop="@drawable/bg_checkbox_icon_menu_1"  
  53.                     android:text="我的考试" />  
  54.   
  55.                 <RadioButton  
  56.                     android:id="@+id/main_tab_message"  
  57.                     style="@style/MMTabButton"  
  58.                     android:layout_weight="1.0"  
  59.                     android:drawableTop="@drawable/bg_checkbox_icon_menu_2"  
  60.                     android:text="我的通知" />  
  61.   
  62.                 <RadioButton  
  63.                     android:id="@+id/main_tab_settings"  
  64.                     style="@style/MMTabButton"  
  65.                     android:layout_weight="1.0"     
  66.                     android:drawableTop="@drawable/bg_checkbox_icon_menu_3"  
  67.                     android:text="设置" />  
  68.             </RadioGroup>  
  69.   
  70.             <TextView  
  71.                 android:id="@+id/main_tab_new_message"  
  72.                 android:layout_width="wrap_content"  
  73.                 android:layout_height="wrap_content"  
  74.                 android:layout_gravity="center_horizontal|top"  
  75.                 android:layout_marginLeft="60dip"  
  76.                 android:layout_marginTop="1dip"  
  77.                 android:background="@drawable/tips"  
  78.                 android:gravity="center"  
  79.                 android:text="1"  
  80.                 android:textColor="#ffffff"  
  81.                 android:textSize="10sp"  
  82.                 android:visibility="gone" />  
  83.         </FrameLayout>  
  84.     </LinearLayout>  
  85.   
  86. </TabHost>  
  • 1
  • 2
  • 下一页

相关内容