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时并不会出现选中状态

          

  • 相关阅读:
    新年放大招:Github 私库免费了!
    阿里启动新项目:Nacos,比 Eureka 更强!
    运行 Spring Boot 应用的 3 种方式
    过了所有技术面,却倒在 HR 一个问题上。。
    hdu 5428 The Factor(数学)
    poj 2385 Apple Catching(dp)
    poj 2229 Sumsets(dp 或 数学)
    poj 1759 Garland (二分搜索之其他)
    poj 3662 Telephone Lines(好题!!!二分搜索+dijkstra)
    poj 3669 Meteor Shower(bfs)
  • 原文地址:https://www.cnblogs.com/zyppac/p/3575126.html
Copyright © 2011-2022 走看看