应用色调以preferenceActivity小部件AppCompat V21 [英] Apply tint to PreferenceActivity widgets with AppCompat v21

查看:214
本文介绍了应用色调以preferenceActivity小部件AppCompat V21的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用复选框preference在preferenceActivity从V21支持库的AppCompat的主题。正如你已经知道,这个最新的磁带库部件像复选框,editTexts,单选按钮等进行着色,在主题中定义的辅助色。在preference屏幕,文本是正确的颜色为specifified我的主题,但复选框和EditText上都没有。看来,当复选框preference实例创建的小部件,但它不是我的主题适用于它。

I'm using CheckboxPreference in a PreferenceActivity and an AppCompat theme from the v21 support library. As you already know, with this latest library widgets like checkboxes, editTexts, radio buttons etc are tinted with the secondary color defined in the theme. In the preference screen, text is in the right color as specifified by my theme, but checkboxes and edittext are not. It seems that when the CheckboxPreference instance creates the widget, it doesn't apply my theme to it.

单选按钮,有色:

从复选框preference复选框,不着色:

Checkbox from the CheckboxPreference, not tinted:

我使用的是与父主题 Theme.AppCompat.Light.NoActionBar 。出现这种情况的,而不是有色线,以preference与小窗口,像的EditText preference说一句,这里的EditText有一个黑色的底线每个子类。如何申请色调由preference子显示的窗口小部件?

I'm using as the parent theme Theme.AppCompat.Light.NoActionBar. This happens to every subclass of Preference with a widget, like EditTextPreference to say one, where the EditText has a black bottom line, instead of a tinted line. How can I apply the tint to the widgets shown by the Preference subclasses?

更新:着色不适用,因为preferenceActivity扩展的框架活动。在工作​​的情况下,我使用的是从支持库的ActionBarActivity。现在的问题是:怎么来的

UPDATE: tinting is not applied because PreferenceActivity extends the framework Activity. In the working case, I'm using an ActionBarActivity from the support library. Now the question is: how come?

推荐答案

到目前为止,我自己的(SAD)的解决方法是从头开始我自己的复选框可绘创建,使用该复选框应该已经在第一染上的颜色的地方。

So far, my own (sad) workaround was to create from scratch my own checkbox drawables, using the colors which the checkbox should have been tinted with in the first place.

在styles.xml:

In styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
...
<!-- edit the checkbox appearance -->
<item name="android:listChoiceIndicatorMultiple">@drawable/my_checkbox</item>
...
</style>

绘制/ my_checkbox.xml:

drawable/my_checkbox.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/checkbox_on" />
    <item android:drawable="@drawable/checkbox_off" />
</selector>

checkbox_on和 checkbox_off`是巴可绘制为选中和未选中状态,显然为每个屏幕像素密度。 如果你不介意尺度的一致性,可绘制的基线(MDPI)的尺寸应该是32PX完整的资产和18像素光广场。

checkbox_on" andcheckbox_off` are the PNG drawables for the selected and unselected states, obviously one for each screen density. If you mind dimension consistency, the baseline (MDPI) dimension of the drawables should be 32px full asset and 18px optical square.

这篇关于应用色调以preferenceActivity小部件AppCompat V21的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆