如何通过样式设置"app:backgroundTint"?

how to set "app:backgroundTint" via style?

我要替换:

<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.

您可以使用:

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

只需使用此代码

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