【问题标题】:Cannot change XML button background color as expected [duplicate]无法按预期更改 XML 按钮背景颜色 [重复]
【发布时间】:2021-05-20 15:32:55
【问题描述】:

我尝试在一个android项目中更改按钮的背景颜色,但似乎无效

这是一个按钮的xml代码:

<Button
                android:id="@+id/comma"
                android:layout_width="0px"
                android:layout_height="90dp"
                android:layout_weight="9"
                android:background="@drawable/button_border"
                android:insetTop="0dp"
                android:insetBottom="0dp"
                android:text="."
                android:textColor="#7ff5f2"
                android:textSize="120px" />

我的可绘制资源文件:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="092c32"
        android:centerColor="#026a6d"
        android:endColor="#092c32"
        android:angle="270" />
    <corners android:radius="3dp" />
    <stroke android:width="5px" android:color="#35f5f2" />
</shape>

This is my expected button background color in my drawable resource file

This is the app design

您可以看到上面的按钮背景颜色看起来类似于默认的紫色,除了有一个渐变,我认为这与我的可绘制资源文件中的渐变有关。

【问题讨论】:

标签: android xml button


【解决方案1】:

这样可以解决问题

 <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/comma"
        android:layout_width="0px"
        android:layout_height="90dp"
        android:layout_weight="9"
        android:background="@drawable/button_border"
        android:insetTop="0dp"
        android:insetBottom="0dp"
        android:text="."
        android:textColor="#7ff5f2"
        android:textSize="120px" />
        />

注意第一行的变化。

【讨论】:

    猜你喜欢
    • 2012-04-25
    • 2014-08-04
    • 1970-01-01
    • 2020-01-01
    • 2015-06-04
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    相关资源
    最近更新 更多