Android Studio 无法覆盖默认主题。

3

我正在尝试将主题分配给具有自定义背景的按钮。它看起来就像这样简单:

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

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

问题出在哪里?


你可以进一步简化你的问题,尝试使用<Button android:background="@drawable/buttonbackground"/>。如果这样做有效,那么问题可能与样式有关。如果这样做无效,则问题可能出在属性上(即你使用了错误的属性)。 - Blundell
你正在使用 Material Theme 还是 App Compat Theme? - Pinakin Kansara
@Blundell 这适用于我当前使用的应用程序主题,但是当我使用默认主题(Theme.MaterialComponents.DayNight.DarkActionBar)时,也不起作用。问题肯定与样式有关,因为当我删除应用程序主题时,按钮可以正常工作。但显然,应用程序看起来很糟糕。 - pretzel
@Pinakin 我正在使用 Theme.AppCompat.Light.NoActionBar。 - pretzel
2个回答

0

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


0

更改您的应用程序主题:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接