我想为按钮添加背景,因为我已经做过好几次了。我有一个具有适当背景的可绘制资源文件。但是,如果我链接它,它不会被接受,而是只会使用一种颜色作为背景。我怀疑它可能是我的 Styles.xml 中的错误,但在这些中没有任何东西被称为太着色。Android Studio 无法识别背景的原因是什么,或者我可以在哪里定义按钮外观的一般主题?我不记得戴过这样的东西。我尝试了类似 EditText 的东西,我在这里没有问题,所以我认为这是一个特定的按钮问题。此外,如果我将背景颜色更改为纯白色,它不会改变任何内容并且仍然显示深蓝色。
更新:如果我将预览样式(预览的上中间)更改为 DialogStyle,则按钮背景会起作用。如果在 der 样式中没有定义任何东西,那怎么可能呢?
更新:这次我添加了一个新版本的按钮,以额外的样式初始化背景。结果是它仍然没有显示正确的颜色。我也用黑色试过,但什么也没发生。
谢谢你的帮助。
按钮
<Button
android:id="@+id/buttonRegistrieren"
android:layout_width="232dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="5dp"
android:background="@drawable/btnbackground"
android:onClick="WriteData"
android:text="@string/Registrieren"
android:textAllCaps="false"
android:textColor="@color/colorWhite"
android:textSize="16dp"></Button>
Run Code Online (Sandbox Code Playgroud)
样式文件
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">@android:color/black</item>
</style>
<style
name="SplashTheme"
parent="AppTheme">
<item name="android:windowFullscreen">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="ButtonStyle" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item> …Run Code Online (Sandbox Code Playgroud)