【问题标题】:how to set "app:backgroundTint" via style?如何通过样式设置“app:backgroundTint”?
【发布时间】:2020-11-15 04:24:18
【问题描述】:

我要更换:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:backgroundTint = "..."
...
    android:orientation="horizontal">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    style="@style/My.Bg.Snackbar.DayNight"
...
    android:orientation="horizontal">

  <style name="My.Bg.Dark" parent="">
    <item name="app:backgroundTint">@color/og_background_dark</item>
  </style>

  <declare-styleable name="My">
    <!-- The background color. -->
    <attr name="app:backgroundTint" format="color" />
  </declare-styleable>
</resources>

但我得到一个错误:

error: resource app:attr/backgroundTint not found.

【问题讨论】:

    标签: java android xml styles android-appcompat


    【解决方案1】:

    你可以使用:

      <style name="My.Bg.Dark" parent="">
        <item name="backgroundTint">@color/og_background_dark</item>
      </style>
    

    【讨论】:

    • 还需要在&lt;attr name="backgroundTint" format="color" /&gt;中定义吗?
    【解决方案2】:

    只需使用此代码

      <style name="MyStyleName" parent="">
        <item name="backgroundTint">@color/green</item>
      </style>
    

    【讨论】:

    • 还需要在&lt;attr name="backgroundTint" format="color" /&gt; 中定义
    猜你喜欢
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-07
    • 2017-11-04
    • 2018-04-04
    • 1970-01-01
    相关资源
    最近更新 更多