小工具没有在Lollipop上着色

Sté*_*ane 8 android android-appcompat android-widget android-5.0-lollipop

我正在为我的应用程序使用appcompat v21.0.3.我做了像这里写的所有内容:android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html

但是在Lollipop(当然还有旧设备上),一些小部件并没有用我的强调色调着色.例如:

  • SwitchCompat着色: switchcompat

  • ListPreference没有着色 在此输入图像描述

  • ProgressDialog没有着色 在此输入图像描述

这是我的代码:

的build.gradle

...
compile 'com.android.support:appcompat-v7:21.0.+'
...
Run Code Online (Sandbox Code Playgroud)

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">
Run Code Online (Sandbox Code Playgroud)

的themes.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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

有人有想法吗?

更新:截至2015年6月,仍然无法正常工作,但我最终使用https://github.com/afollestad/material-dialogs.对包括ListPreferences在内的对话框非常有用.

Mur*_*ain 30

请遵循以下指南

除非另有说明,否则以下所有着色均适用于使用AppCompat v21的Lollipop和pre-Lollipop.要使用这些属性的支持版本,请删除android命名空间.例如,"android:colorControlNormal"变为"colorControlNormal".对于运行Lollipop的设备,这些属性将传播到android命名空间内的相应属性.通过包含"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"
Run Code Online (Sandbox Code Playgroud)

默认情况下,PS着色仅适用于列入白名单的股票动作图标(请参阅TintManager源代码).例如,后退箭头图标"abc_ic_ab_back_mtrl_am_alpha"是有色的,但复制该确切文件并重命名它将导致图标在拍摄随机图像时没有着色并将其重命名为"abc_ic_ab_back_mtrl_am_alpha"将导致其着色.通过<bitmap>在drawable中创建xml文件并应用该"android:tint"属性,可以在Lollipop中以XML格式完成着色.这个图标可用于Lollipop和pre-Lollipop,但它只会在Lollipop中着色.也可以使用a以编程方式完成操作图标的着色ColorFilter.

资源


Mar*_*ton 12

您通常应该使用自己的进度条而不是对话框,然后您可以制作适用于L和pre-L的着色版本,如下所示:

public class TintedProgressBar extends ProgressBar {
    public TintedProgressBar(Context context) {
        super(context);
        init();
    }

    public TintedProgressBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TintedProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public void init() {
        getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.primary), PorterDuff.Mode.SRC_IN);
        getProgressDrawable().setColorFilter(getResources().getColor(R.color.primary), PorterDuff.Mode.SRC_IN);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果你真的想在对话框中更改颜色,可以找到嵌套的进度条 dialog.findViewById(android.R.id.progess)


And*_*y T 5

为了改变Progress Dialog drawable的颜色,我使用了以下解决方法:我创建了AppCompat警告对话框基本样式

    <style name="CustomAppCompatAlertDialogStyle"    parent="Theme.AppCompat.Light.Dialog.Alert">
            <item name="colorAccent">@color/defaultColor</item>
            <item name="android:indeterminateTint">?attr/colorAccent</item>
            <item name="android:indeterminateTintMode">src_in</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

然后将这些主题应用于Progress Dialog:

mProgressDialog = new ProgressDialog(this, R.style.CustomAppCompatAlertDialogStyle);
Run Code Online (Sandbox Code Playgroud)


Fen*_*Dai 1

尝试属性colorControlActivated:

主题.xml

<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>
    <item name="colorControlActivated">#a32b30</item>
</style>
Run Code Online (Sandbox Code Playgroud)