您的位置:首页 > 移动开发 > Android开发

xml实现多标签页面

2015-12-28 17:38 435 查看
完全由xml配置TabHost,只需要自己做页面切换的事件响应便是。demo程序下载地址:

http://download.csdn.net/detail/zm_android_team/9380754



核心代码:

<RadioGroup

        android:id="@+id/radio_group"

        android:layout_width="match_parent"

        android:layout_height="40dp"

        android:divider="@drawable/divider_line_vertical"

        android:orientation="horizontal"

        android:showDividers="middle" >

        <RadioButton

            android:id="@+id/undo"

            android:layout_width="0dp"

            android:layout_height="match_parent"

            android:layout_weight="1"

            android:background="@drawable/selector_tab_item"

            android:button="@null"

            android:checked="true"

            android:gravity="center"

            android:text="新建"

            android:textColor="@drawable/selector_text_color_tab" />

        <RadioButton

            android:id="@+id/doing"

            android:layout_width="0dp"

            android:layout_height="match_parent"

            android:layout_weight="1"

            android:background="@drawable/selector_tab_item"

            android:button="@null"

            android:gravity="center"

            android:text="进行中"

            android:textColor="@drawable/selector_text_color_tab" />

selector_text_color_tab.xml

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">

    <!-- 获取焦点时的文本颜色 -->

    <item android:state_checked="true" android:color="#4A8DE6"/>

    <!-- 默认时的文本颜色 -->

    <item android:color="#575757"/>

</selector>

selector_tab_item.xml

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">

    <!-- 获取焦点时的图片背景 -->

    <item android:drawable="@drawable/bottom_stroke_checked" android:state_checked="true" />

    <!-- 默认时的图片背景 -->

    <item android:drawable="@drawable/bottom_stroke"/>

</selector>

bottom_stroke_checked.xml

<?xml version="1.0" encoding="UTF-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 连框颜色值 -->

    <item>

        <shape>

            <solid android:color="#4A8DE6" />

        </shape>

    </item>

    <!-- 主体背景颜色值 -->

    <item

        android:bottom="2dp">

        <shape>

            <solid android:color="#FFFFFF" />

        </shape>

    </item>

</layer-list>

bottom_stroke.xml

<?xml version="1.0" encoding="UTF-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 连框颜色值 -->

    <item>

        <shape>

            <solid android:color="#CCCCCC" />

        </shape>

    </item>

    <!-- 主体背景颜色值 -->

    <item android:bottom="2dp">

        <shape>

            <solid android:color="#FFFFFF" />

        </shape>

    </item>

</layer-list>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android Tab