RadioButton设置selector颜色和图片选择器

     今天使用RadioButton的时候,遇到按钮设置颜色和图片选择器无效的问题,网上也找了好久也弄不好。其实就是state_checked的问题,记得以前使用button的时候使用state_selected是可以的,不知道RadioButton为什么不行。今天把它记下来,以免大家也犯同样的错误!

1、首先来看selector文件,这是图片的

xmlns:android="http://schemas.android.com/apk/res/android">
    android:drawable="@drawable/main_3d_green" android:state_checked="true" />
    android:drawable="@drawable/main_3d" />

2.这是设置文字颜色的

xmlns:android="http://schemas.android.com/apk/res/android">
    android:color="@color/colorGreenPrimary" android:state_checked="true" />
    android:color="@color/color_80" />

3.这是RadioButton的布局和style文件,checked="true"是默认选中的按钮

    android:id="@+id/rBtn_3d"
    style="@style/main_radioButton_style"
    android:drawableTop="@drawable/select_3d_btn_img"
    android:text="3D相册"
    android:textColor="@drawable/select_main_tv_color"
    android:checked="true"/>

4.最后插播一条toolbar标题颜色的设置:

因为toolbar的字体默认是黑色的,丑得要死;所以我们把它改成白色的,这里textColorPrimary是关键。百度上好多说用"actionMenuTextColor",不加android前缀什么的,统统不行!估计是Level的问题吧!

xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorGreenPrimary"
    android:theme="@style/toolbarTheme">


你可能感兴趣的:(andriod)