我正在为我的应用程序使用 appcompat v21.0.3。我做了这里写的所有事情:android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html
但是在 Lollipop 上(当然还有旧设备),一些小部件没有用我的强调色着色。例如:
SwitchCompat 有色:
ListPreference 未着色
ProgressDialog 未着色
这是我的代码:
build.gradle
...
compile 'com.android.support:appcompat-v7:21.0.+'
...
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CET"
android:hardwareAccelerated="true"
tools:replace="label">
主题.xml
<resources>
<style name="CET" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
</resources>
colors.xml
<resources>
<!-- App branding color -->
<color name="primary">#a32b30</color>
<!-- Darker variant for status bar and contextual app bars -->
<color name="primary_dark">#000000</color>
<!-- Theme UI constrols like checkboxes and text fields -->
<color name="accent">#a32b30</color>
</resources>
有人有想法吗?
更新:截至 2015 年 6 月,仍然无法正常工作,但我最终使用了 https://github.com/afollestad/material-dialogs .非常适合对话框,包括 ListPreferences。
最佳答案
遵循以下指南
除非另有说明,否则以下所有着色都适用于使用 AppCompat v21 的 Lollipop 和 pre-Lollipop。要使用这些属性的支持版本,请删除 android 命名空间。例如,“android:colorControlNormal”变为“colorControlNormal”。这些属性将传播到运行 Lollipop 的设备的 android 命名空间内的相应属性。任何异常(exception)情况都将通过包含“android:”前缀来注明。
All Clickable Views:
-----------
* ripple effect (Lollipop only) -- "colorControlHighlight"
Status Bar:
------------
* background (Lollipop only) - "colorPrimaryDark"
Navigation Bar:
----------------
* background (Lollipop only) - "android:navigationBarColor"
EditText:
----------
* underline (unfocused) -- "colorControlNormal"
* underline overlay (focus) -- "colorAccent"
* cursor -- "colorAccent"
* text color -- "android:textColorPrimary"
CheckBox:
----------
* box unchecked -- "colorControlNormal"
* box checked -- "colorAccent"
RadioButton:
-------------
* unselected -- "colorControlNormal"
* selected -- "colorAccent"
* ripple effect (Lollipop only) -- "colorControlHighlight"
SwitchCompat:
-------------
* thumb switch off -- "colorSwitchThumbNormal"
* thumb switch on -- "colorAccent"
* track overlay (when switched on) -- "colorAccent"
Spinner:
---------
* indicator (not pressed) -- "colorControlNormal"
* indicator (pressed) -- "colorAccent"
* selected entry text color (Lollipop only) -- "android:textColorPrimary"
ActionBar:
-----------
* background -- "colorPrimary"
* title color -- "android:textColorPrimary"
* overflow icon -- "android:textColorPrimary"
* up button -- "android:textColorPrimary"
* action icons -- "android:textColorPrimary" †
* overflow menu background -- "android:colorBackground"
* overflow text color -- "android:textColorPrimary"
Toolbar (Theme Overlay should be used):
----------------------------------------
* background -- must be set manually in XML. Can do (android:background="?attr/colorPrimary")
* overflow icon -- "android:textColorPrimary"
* navigation icon -- "android:textColorPrimary" †
* action icons -- "android:textColorPrimary" †
* overflow menu background -- "android:colorBackground"
* overflow text color -- "android:textColorPrimary"
附言默认情况下,着色仅适用于列入白名单的股票操作图标(参见 TintManager
源代码)。例如,后退箭头图标 "abc_ic_ab_back_mtrl_am_alpha"
是有色的,但是复制那个确切的文件并重命名它会导致在拍摄随机图像并将其重命名为 "abc_ic_ab_back_mtrl_am_alpha"
时图标不会被着色。会导致它被着色。通过创建 <bitmap>
,可以在 Lollipop 的 XML 中完成着色。 drawable 中的 xml 文件并应用 "android:tint"
属性。此图标可用于 Lollipop 和 pre-Lollipop,但只会在 Lollipop 中着色。 Action 图标的着色也可以使用 ColorFilter
以编程方式完成。 .
关于android - Lollipop 上未着色的小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27939440/