【发布时间】:2021-09-24 18:07:46
【问题描述】:
我正在尝试将主题分配给具有自定义背景的按钮。它看起来就像这样:
<style name="button">
<item name="android:background">@drawable/buttonbackground</item>
</style>
<Button android:theme="@style/button"/>
按钮保持其原始背景,但对于 TextView,例如,它可以工作。
<TextView android:theme="@style/button"/>
问题出在哪里?
【问题讨论】:
-
您可以进一步简化您的问题并尝试
<Button android:background="@drawable/buttonbackground"/>。如果这确实有效,那么问题与样式有关。如果这不起作用,那么问题出在属性上(因为您使用了错误的属性) -
您使用的是 Material Theme 还是 App Compat Theme?
-
@Blundell 这适用于我当前使用的应用程序主题,但是当我使用默认主题(Theme.MaterialComponents.DayNight.DarkActionBar)时,它也不起作用。问题肯定出在样式上,因为当我删除应用程序主题时,按钮会起作用。但显然该应用程序看起来像垃圾。
-
@Pinakin 我正在使用 Theme.AppCompat.Light.NoActionBar
标签: android android-studio android-layout