安卓工作室无法覆盖默认主题背景



我正在尝试为具有自定义背景的按钮分配一个主题。它看起来很简单:

<style name="button">
<item name="android:background">@drawable/buttonbackground</item>
</style>‌
<Button android:theme="@style/button"/>

该按钮保持其原始背景,但对于TextView来说,它是有效的。

<TextView android:theme="@style/button"/>

问题出在哪里?

更改应用程序主题:

<style name="Theme" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
.....
</style>

在AndroidManifest.xml中使用@style/Theme:

<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme"
>

这是一个非常简单的解决方案,只需使用style而不是android:theme。我只是不知道它的存在。

最新更新