无法按预期更改 XML 按钮背景颜色
Cannot change XML button background color as expected
我尝试更改 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
你可以看到上面的按钮背景颜色看起来和默认的紫色很相似,除了有一个渐变,我认为这与我的可绘制资源文件中的渐变有关。
这可能会解决问题
<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" />
/>
注意第一行的变化。
我尝试更改 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
你可以看到上面的按钮背景颜色看起来和默认的紫色很相似,除了有一个渐变,我认为这与我的可绘制资源文件中的渐变有关。
这可能会解决问题
<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" />
/>
注意第一行的变化。