更改Android AppCompatRadioButton控件的样式和颜色

来源:互联网 发布:各种字体软件下载 编辑:程序博客网 时间:2024/05/23 01:22

准确来讲是更改它的主题颜色,默认启用的是colorPrimary的值

1.在你的build.gradle 文件中引入最新的appcompat依赖包

  dependencies {         compile 'com.android.support:appcompat-v7:X.X.X' // X.X.X 为版本号     }

2.使你的activity继承android.support.v7.app.AppCompatActivity

public class MainActivity extends AppCompatActivity {   ...}

3.在styles.xml文件中定义你想要的样式,格式如下

<style name="MyRadioButton" parent="Theme.AppCompat.Light">     <item name="colorControlNormal">@color/white</item>    <item name="colorControlActivated">@color/green</item></style>

4.在使用AppCompatRadioButton的地方使用属性android:theme应用自定义的样式

<android.support.v7.widget.AppCompatRadioButton     android:id="@+id/r3"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:theme="@style/MyRadioButton" />

效果:


参考:

http://www.materialdoc.com/radio-button/
http://stackoverflow.com/questions/26562609/change-widgets-color-appcompat-21

0 0
原创粉丝点击