【问题标题】:How to apply ProgressBarStyle?如何应用 ProgressBarStyle?
【发布时间】:2018-11-13 16:01:05
【问题描述】:

我正在尝试将主题应用于我的应用程序中的所有进度条。在清单中,我应用了一个名为 AppTheme 的自定义主题。在这种风格中,我添加了一个额外的progressBarStyle 项目,如下所示:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="android:progressBarStyle">@style/my_progress_bar</item>
</style>

我这样定义自定义栏进度样式:

<style name="my_progress_bar" parent="Base.Widget.AppCompat.ProgressBar">
    <item name="android:indeterminateTint">@color/app_black</item>
    <item name="android:indeterminateTintMode">src_in</item>
</style>

如果我将此样式应用于单个 ProgressBar 视图,它会起作用,但我想通过 AppTheme 在我的清单中应用它,这样我就不必为应用程序中的每个进度条指定相同的 tint 和 tintMode。我正在使用运行 API 25 的设备。

我做错了什么?感谢您提供任何见解。

编辑:经过进一步调查,由于某种原因,将样式添加到 AppTheme 不会传播到清单。如果我完全用我的进度条样式替换 AppTheme,它就可以工作。但我仍然需要AppTheme 中定义的样式。 这有效: <application ... android:theme="@style/my_progress_bar">

但这不是: <application ... android:theme="@style/AppTheme">

有趣的是,如果我删除 AppTheme 中除了我定义的进度条样式之外的所有内容,它就不起作用。 android中是否存在嵌套样式的错误?当我将它传递给这个 AppTheme 时,我的清单没有看到定义的 progressBarStyle:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:progressBarStyle">@style/my_progress_bar</item>
</style>

【问题讨论】:

    标签: android android-manifest android-theme android-progressbar


    【解决方案1】:

    在您的清单文件中,您有以下内容:

    <application
            android:name="app"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme">
    
    .......
    </application>
    

    将以下内容添加到您的 style.xml 文件中的 AppTheme:

    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
            <!--This will change the color of your progress bar throughout the whole app-->
            <item name="colorControlActivated">@color/app_black</item>
    </style>
    

    【讨论】:

    • 不幸的是,colorControlActivated item 确实为我解决了这个问题
    • 做还是不做?
    • 抱歉,我的意思是没有
    猜你喜欢
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多