我正在尝试将主题分配给具有自定义背景的按钮。它看起来就像这样简单:
<style name="button">
<item name="android:background">@drawable/buttonbackground</item>
</style>
<Button android:theme="@style/button"/>
<TextView android:theme="@style/button"/>
问题出在哪里?
我正在尝试将主题分配给具有自定义背景的按钮。它看起来就像这样简单:
<style name="button">
<item name="android:background">@drawable/buttonbackground</item>
</style>
<Button android:theme="@style/button"/>
<TextView android:theme="@style/button"/>
问题出在哪里?
嗯,这是一个非常简单的解决方案,只需使用style
而不是android:theme
。我只是不知道它的存在。
更改您的应用程序主题:
<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"
>
<Button android:background="@drawable/buttonbackground"/>
。如果这样做有效,那么问题可能与样式有关。如果这样做无效,则问题可能出在属性上(即你使用了错误的属性)。 - Blundell