当前位置:操作系统 > 安卓/Android >>

Android应用底部导航栏(选项卡)实例

现在很多android的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用TabHost组件来自定义一个底部的导航栏的功能。
我们先看下该demo实例的框架图:

\
 
其中各个类的作用以及资源文件就不详细解释了,还有资源图片(在该Demo中借用了其它应用程序的资源图片)也不提供了,大家可以自行更换自己需要的资源图片。直接上各个布局文件或各个类的代码:
[1]  res/layout目录下的maintabs.xml 源码:
[html]
<?xml version="1.0" encoding="UTF-8"?> 
<TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" 
  xmlns:android="http://schemas.android.com/apk/res/android"> 
    <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
        <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:visibility="gone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0" /> 
            <RadioGroup  
                android:gravity="center_vertical" android:layout_gravity="bottom" android:orientation="horizontal" android:id="@id/main_radio" android:background="@drawable/maintab_易做图_bg"  
                android:layout_width="fill_parent" android:layout_height="wrap_content"> 
                <RadioButton  android:id="@id/radio_button0" android:layout_marginTop="2.0dip" android:text="@string/main_home" android:drawableTop="@drawable/icon_1_n" style="@style/main_tab_bottom" /> 
                <RadioButton  android:id="@id/radio_button1" android:layout_marginTop="2.0dip" android:text="@string/main_news" android:drawableTop="@drawable/icon_2_n" style="@style/main_tab_bottom" /> 
                <RadioButton  android:id="@id/radio_button2" android:layout_marginTop="2.0dip" android:text="@string/main_manage_date" android:drawableTop="@drawable/icon_3_n" style="@style/main_tab_bottom" /> 
                <RadioButton  android:id="@id/radio_button3" android:layout_marginTop="2.0dip" android:text="@string/main_friends" android:drawableTop="@drawable/icon_4_n" style="@style/main_tab_bottom" /> 
                <RadioButton  android:id="@id/radio_button4" android:layout_marginTop="2.0dip" android:text="@string/more" android:drawableTop="@drawable/icon_5_n" style="@style/main_tab_bottom" /> 
            </RadioGroup> 
    </LinearLayout> 
</TabHost> 
[2] res/drawable 下的home_btn_bg.xml 源码:www.zzzyk.com
[html]
<?xml version="1.0" encoding="UTF-8"?> 
<selector 
  xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_focused="true" android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/home_btn_bg_s" /> 
    <item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/home_btn_bg_s" /> 
    <item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/home_btn_bg_d" /> 
    <item android:drawable="@drawable/transparent" /> 
</selector> 
[3] res/values 下的源码:
dimens.xml源码
[html]
<?xml version="1.0" encoding="utf-8"?> 
<resources> 
 
    <dimen name="bottom_tab_font_size">10.0sp</dimen> 
    <dimen name="bottom_tab_padding_up">5.0dip</dimen> 
    <dimen name="bottom_tab_padding_drawable">2.0dip</dimen> 
    <dimen name="switch_logo_bottom_padding">30.0sp</dimen> 
    <dimen name="widget_height">100.0dip</dimen> 
    <dimen name="sta_height">48.0dip</dimen> 
    <dimen name="large_padding_length">20.0dip</dimen> 
    <dimen name="widget_write_margin_top">19.0dip</dimen> 
    <dimen name="widget_write_margin_left">10.0dip</dimen> 
    <dimen name="widget_content_margin_top">20.0dip</dimen> 
    <dimen name="widget_content_margin_left">10.0dip</dimen> 
    <dimen name="widget_logo_size">35.0dip</dimen> 
    <dimen name="title_height">74.0dip</dimen> 
    <dimen name="new_blog_size">70.0dip</dimen> 
    <dimen name="emotion_item_view_height">13.299988dip</dimen> 
    <dimen name="splash_test_top_margin_top">20.0dip</dimen> 
    <dimen name="splash_test_center_margin_right">0.0dip</dimen> 
    <dimen name="title_text_size">20.0sp</dimen> 
    <dimen name="normal_padding_length">10.0dip</dimen> 
    <dimen name="no_result_padding_length">50.0dip</dimen> 
 
</resources> 
 
drawables.xml源码:
[html]
<?xml version="1.0" encoding="utf-8"?> 
<resources> 
 
    <item type="drawable" name="ltgray">#fff4f4f4</item> 
    <item type="drawable" name="ltyellow">#fffff4db</ite
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,