【问题标题】:5.1 Crash - A TaskDescription's primary color should be opaque5.1 崩溃 - TaskDescription 的原色应该是不透明的
【发布时间】:2015-05-23 21:05:34
【问题描述】:

我已经在我的应用程序中实现了材料设计,它在

     FATAL EXCEPTION main
 Process com.test.test, PID 3195
 java.lang.RuntimeException Unable to start activity ComponentInfo{com.test.test/com.test.test.MainActivity} java.lang.RuntimeException A TaskDescription's primary color should be opaque
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java2298)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java2360)
    at android.app.ActivityThread.access$800(ActivityThread.java144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java1278)
    at android.os.Handler.dispatchMessage(Handler.java102)
    at android.os.Looper.loop(Looper.java135)
    at android.app.ActivityThread.main(ActivityThread.java5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java694)
 Caused by java.lang.RuntimeException A TaskDescription's primary color should be opaque
    at android.app.ActivityManager$TaskDescription.<init>(ActivityManager.java536)
    at android.app.Activity.onApplyThemeResource(Activity.java3677)
    at android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java140)
    at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java85)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java2244)
    ... 10 more

这是我的风格:

    <resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.


    -->


    <!-- All customizations that are NOT specific to a particular API-level can go here. -->

    <style name="AppTheme" parent="@style/Theme.AppCompat.NoActionBar">

        <!-- All customizations that are NOT specific to a particular API-level can go here. -->

        <item name="colorPrimaryDark">#4DFF9800</item>
        <item name="colorPrimary">#4D607D8B</item>
    </style>

</resources>

如果有人能给我一些指导,那将非常感谢。

【问题讨论】:

    标签: android crash material-design


    【解决方案1】:

    您不能在原色中使用 alfa。原色必须是不透明的。

    变化:

    <item name="colorPrimaryDark">#4DFF9800</item>
    <item name="colorPrimary">#4D607D8B</item>
    

    <item name="colorPrimaryDark">#FF9800</item>
    <item name="colorPrimary">#607D8B</item>
    

    res/values-v21/style.xml 文件中的 api 21

    【讨论】:

    • 我自己没有使用这个解决方案。我测试了android 6.0
    • @SathishKumarJ 你能用你的代码创建要点吗?
    • 在这里查看我的问题stackoverflow.com/questions/41298162/…
    • 请澄清在哪些情况下它必须是不透明的,因为我可以在 Marshmallow 6.0.1 上使用透明颜色作为 colorPrimary 没有任何问题.. 我没有棒棒糖设备所以无法测试它
    • 安卓6没问题,安卓4.4也没问题,但是安卓5.1抛出这个异常!!!难道没有一个不需要降低我的应用颜色的好解决方案吗?
    【解决方案2】:

    解决这个问题的简单方法是删除colors.xml中应用于原色的不透明

    当 opaque 应用于原色时,颜色代码看起来像这样“#aca688ff”,它必须是 ex:“#F50057”(6 个字母数字代码,没有 opaque)。

    希望以上解决方案能帮助您解决问题。

    【讨论】:

      【解决方案3】:

      @Konrad Krakowiak 是对的。
      可以看android.app.ActivityManager#TaskDescription的源码。

      /**
          * Creates the TaskDescription to the specified values.
          *
          * @param label A label and description of the current state of this task.
          * @param icon An icon that represents the current state of this task.
          * @param colorPrimary A color to override the theme's primary color. This color must be opaque.
          */
          public TaskDescription(String label, Bitmap icon, int colorPrimary) {
            if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
              throw new RuntimeException("A TaskDescription's primary color should be opaque");
            }
      
            mLabel = label;
            mIcon = icon;
            mColorPrimary = colorPrimary;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多