Nim*_*a G 63 android material-design
我已经更新了我的项目以使用最新的appcompat支持库,新版本使用了材料设计复选框和单选按钮.我的应用程序是黑暗的主题,复选框是黑色,很难看到.我试图根据维护兼容性改变颜色,但到目前为止没有任何作用.
RES /值/ styles.xml
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
<!-- customize the color palette -->
<item name="colorAccent">@color/silver</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在build.gradle中:
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
}
.....
.....
compile 'com.android.support:appcompat-v7:21.0.0'
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中:
<application
android:name="ee.mtakso.App"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
Run Code Online (Sandbox Code Playgroud)
复选框,editTexts,radiobuttons等保持黑色.
我不知道这是否有很大的不同,但我正在使用的radiobuttons和复选框是a CheckedTextView,如下所示:
单(单选按钮): android:checkMark="?android:attr/listChoiceIndicatorSingle"
多(复选框): android:checkMark="?android:attr/listChoiceIndicatorMultiple"
由于这些黑色材料可以绘制,我不认为这个问题来自于它们.
pau*_*lab 126
我对未经检查的CheckBoxes和RadioButtons有类似的问题.我找到了解决方案,当我发现控件从它们的"关闭"颜色
<item name="android:textColorSecondary">@color/secondary_text</item>
编辑:
指定,如果您的应用程序或活动的主题继承了L's AppCompat(Dark/Light/Light.DarkActionBar)之一,您可以设置:
<style name="SampleTheme" parent="Theme.AppCompat">
<item name="colorAccent">@color/green</item>
<item name="android:textColorSecondary">@color/red</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这就是结果:

注意:当你得到不同的效果时,你可能会使用"错误的"主题 - 确保你正确设置它.
Cod*_*sed 37
我相信这是AppCompat主题中的一个错误.我的解决方法是在xml布局文件中为每个CheckBox添加两行代码.
android:button="@drawable/abc_btn_check_material"
android:buttonTint="@color/colorAccent"
Run Code Online (Sandbox Code Playgroud)
你真的不想直接引用abc_ drawables,但在这种情况下我找不到其他解决方案.
这也适用于RadioButton小部件!您只需使用 abc_btn_radio_material而不是abc_btn_check_material
Dan*_* S. 18
我这样做至少改变了一个复选框的边框:
<style name="checkBoxComponent" parent="AppTheme">
//Checked color
<item name="colorAccent">@color/blueBackground</item>
//Checkbox border color
<item name="android:textColorSecondary">@color/grayBorder</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在我的布局
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/checkBoxComponent"
android:text="Yay" />
Run Code Online (Sandbox Code Playgroud)
仍在弄清楚如何获得复选框的背景.希望能帮助到你.
小智 14
我和你有同样的问题.我再次看了AppCompat v21 - 前棒棒糖设备的材料设计!
我发现这"你的所有活动必须从ActionBarActivity扩展,ActionBarActivity从v4支持库的FragmentActivity扩展,所以你可以继续使用片段." .
所以我将我的活动改为ActionBarActivity,它解决了我的问题.我希望它也会解决你的问题.
我一直在寻找解决方案而且我找到了它.
步骤1
扩展ActionBarActivity
public static class MyActivity extends ActionBarActivity {
//...
}
Run Code Online (Sandbox Code Playgroud)
步骤2
在样式文件中写入两个值
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorAccent">#009688</item>
<item name="android:textColorSecondary">#757575</item>
</style>
Run Code Online (Sandbox Code Playgroud)
colorAccent - 选中颜色
android:textColorSecondary - 未选中颜色
步骤3
在AndroidManifest.xml中设置主题
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.radiobutton"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
....
<activity android:name=".activity.MyActivity "
android:theme="@style/MyTheme"/>
.....
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
结果
Android 5
Android 4.2.2

1.在styles.xml文件中声明自定义样式.
<style name="CustomStyledRadioButton" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">@color/red</item>
<item name="colorControlActivated">@color/red_pressed</item>
</style>
Run Code Online (Sandbox Code Playgroud)
2.通过android:theme属性将此样式应用于RadioButton.
<RadioButton android:id="@+id/rb_option1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:gravity="left"
android:lineSpacingExtra="10dp"
android:padding="10dp"
android:text="Option1"
android:textColor="@color/black"
android:theme="@style/CustomStyledRadioButton"/>
Run Code Online (Sandbox Code Playgroud)
100%工作
只需为您的RadioButton创建一个样式并更改colorAccent,如下所示:
<style name="RadioButtonTeal" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">@color/md_teal_600</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后只需将此样式添加到AppCompatRadioButton:
<android.support.v7.widget.AppCompatRadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/RadioButtonTeal" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
68744 次 |
| 最近记录: |