英文:
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.
英文:
I want to replace:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:backgroundTint = "..."
...
android:orientation="horizontal">
with
<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">
and
<style name="My.Bg.Dark" parent="">
<item name="app:backgroundTint">@color/og_background_dark</item>
</style>
and
<declare-styleable name="My">
<!-- The background color. -->
<attr name="app:backgroundTint" format="color" />
</declare-styleable>
</resources>
but I get an error:
error: resource app:attr/backgroundTint not found.
答案1
得分: 2
你可以使用:
<style name="My.Bg.Dark" parent="">
<item name="backgroundTint">@color/og_background_dark</item>
</style>
英文:
You can use:
<style name="My.Bg.Dark" parent="">
<item name="backgroundTint">@color/og_background_dark</item>
</style>
答案2
得分: 0
只使用这段代码
<style name="MyStyleName" parent="">
<item name="backgroundTint">@color/green</item>
</style>
英文:
just use this code
<style name="MyStyleName" parent="">
<item name="backgroundTint">@color/green</item>
</style>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论