zoukankan      html  css  js  c++  java
  • android selector RadioButton实现Tab功能

        1.创建xml文件

                 在res下创建drawable 文件夹,在drawable文件夹下创建my_selector.xml

                 my_selector.xml内容如下:    

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

                            <item android:state_enabled="true" android:state_focused="true"

                                     android:state_pressed="false" android:drawable="@drawable/tab_normal" />  

                            <item android:state_enabled="true" android:state_pressed="true"

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

                                      android:drawable="@drawable/tab_press" />
                             <item android:drawable="@drawable/tab_normal"/>
                     </selector>

                  注: tab_normal为未选中状态下图片, tab_press为选中状态下图片

          2.将my_selector.xml设为RadioButton的背景       

                   <RadioGroup
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" >

                        <RadioButton
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:background="@drawable/my_selector"

                                 android:button="@null"/>  //去除RadioButton 左侧小圆圈

                        <RadioButton
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:background="@drawable/my_selector"

                                android:button="@null" />

                     </RadioGroup>

             

           这样就可以实现Tab功能,需要的注意的一点是,使用Button时并不会出现选中状态

          

  • 相关阅读:
    HDU2037
    python爬取邮箱
    HDU1058
    opengl 光照
    HDU1421
    <cocos2dx for window phone>一个简单的打地鼠游戏
    <cocos2dx for wp7>使用cocos2dx制作基于Tile地图的游戏:加入敌人和战斗(三)
    <WP7>(五)手把手教你写天气预报程序:ApplicationBar的使用和ListPicker的数据绑定
    <cocos2dx for wp7>在cocos2dx里面手势识别
    <cocos2dx for wp7>使用cocos2dx制作基于Tile地图的游戏:碰撞检测和收集物品(二)
  • 原文地址:https://www.cnblogs.com/zyppac/p/3575126.html
Copyright © 2011-2022 走看看