码迷,mamicode.com
首页 > 其他好文 > 详细

主题和选择器

时间:2016-02-08 21:15:02      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

今天在做底部tab的时候因为样式都一样 所以就自定义一个style 这样省的写很多重复的样式(懒懒懒懒),zai9values/styles.xml 里添加 radiobutton样式:

 

    <style name="BottomTabStyle">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_weight">1</item>
        <item name="android:button">@null</item>
        <item name="android:gravity">center</item>
        <item name="android:padding">5dp</item>
        <item name="android:drawablePadding">3dp</item>
        <item name="android:textColor">@color/txt_bottom_tab_selector</item>
    </style>

 

颜色选择器再res/color里 添加txt_bottom_tab_selector.xml:

 

 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="true" android:color="#f00"></item>//state_checked是选择后 state_pressed是按下 <item android:color="#fff"></item> //默认 </selector>

 

 图片选择器:res/drawable下

 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

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

</selector>

 

 

再layout中 用style来引入主题样式: drawabletop @drawable 引入图片选择器

       <RadioButton
            android:id="@+id/rb_home"
            style="@style/BottomTabStyle"
            android:drawableTop="@drawable/btn_home_selector"
            android:checked="true"
            android:text="首页" />

 一点偷懒小技巧

 

主题和选择器

标签:

原文地址:http://www.cnblogs.com/AceIsSunshineRain/p/5185167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!