歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android底部菜單欄demo

Android底部菜單欄demo

日期:2017/3/1 10:15:28   编辑:Linux編程

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. <LinearLayout
  7. android:layout_width="fill_parent"
  8. android:layout_height="fill_parent"
  9. android:background="@color/bg_gray"
  10. android:orientation="vertical" >
  11. <FrameLayout
  12. android:id="@android:id/tabcontent"
  13. android:layout_width="fill_parent"
  14. android:layout_height="0.0dip"
  15. android:layout_weight="1.0" />
  16. <TabWidget
  17. android:id="@android:id/tabs"
  18. android:layout_width="fill_parent"
  19. android:layout_height="wrap_content"
  20. android:layout_weight="0.0"
  21. android:visibility="gone" />
  22. <FrameLayout
  23. android:layout_width="fill_parent"
  24. android:layout_height="wrap_content" >
  25. <RadioGroup
  26. android:id="@+id/main_tab_group"
  27. android:layout_width="fill_parent"
  28. android:layout_height="wrap_content"
  29. android:layout_gravity="bottom"
  30. android:background="@drawable/bottom1"
  31. android:gravity="bottom"
  32. android:orientation="horizontal"
  33. >
  34. <RadioButton
  35. android:id="@+id/main_tab_addExam"
  36. style="@style/MMTabButton"
  37. android:layout_weight="1.0"
  38. android:drawableTop="@drawable/bg_checkbox_icon_menu_0"
  39. android:text="添加考試" />
  40. <RadioButton
  41. android:id="@+id/main_tab_myExam"
  42. style="@style/MMTabButton"
  43. android:layout_weight="1.0"
  44. android:checked="true"
  45. android:drawableTop="@drawable/bg_checkbox_icon_menu_1"
  46. android:text="我的考試" />
  47. <RadioButton
  48. android:id="@+id/main_tab_message"
  49. style="@style/MMTabButton"
  50. android:layout_weight="1.0"
  51. android:drawableTop="@drawable/bg_checkbox_icon_menu_2"
  52. android:text="我的通知" />
  53. <RadioButton
  54. android:id="@+id/main_tab_settings"
  55. style="@style/MMTabButton"
  56. android:layout_weight="1.0"
  57. android:drawableTop="@drawable/bg_checkbox_icon_menu_3"
  58. android:text="設置" />
  59. </RadioGroup>
  60. <TextView
  61. android:id="@+id/main_tab_new_message"
  62. android:layout_width="wrap_content"
  63. android:layout_height="wrap_content"
  64. android:layout_gravity="center_horizontal|top"
  65. android:layout_marginLeft="60dip"
  66. android:layout_marginTop="1dip"
  67. android:background="@drawable/tips"
  68. android:gravity="center"
  69. android:text="1"
  70. android:textColor="#ffffff"
  71. android:textSize="10sp"
  72. android:visibility="gone" />
  73. </FrameLayout>
  74. </LinearLayout>
  75. </TabHost>
Copyright © Linux教程網 All Rights Reserved