你好,游客 登录 注册 搜索
背景:
阅读新闻

Android底部菜单栏demo

[日期:2012-07-25] 来源:csdn  作者:wangkuifeng0118 [字体:大 中 小]

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

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

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

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

  1. <?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>  
  • linux
    相关资讯       Android开发基础 
    本文评论   查看全部评论 (1)
    表情: 表情 姓名: 字数

           

    评论声明
    • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
    • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
    • 本站管理人员有权保留或删除其管辖留言中的任意内容
    • 本站有权在网站内转载或引用您的评论
    • 参与本评论即表明您已经阅读并接受上述条款
    第 1 楼
    * 匿名 发表于 2013/12/6 16:18:46
    有用,谢谢