通过覆盖androidstudio默认按钮样式,将按钮样式更改为自定义xml文件



我想为我的按钮定制按钮设计,但android stdio有默认的按钮样式,它是紫色的,我无法删除它。

我的xml设计代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="@color/teal_200"
android:endColor="@color/purple_200"
android:angle="270"/>
<corners android:radius="30dp"/>
</shape>

默认按钮样式为:默认按钮图像

我想要我的按钮的设计:我的按钮设计

您可以添加

android:centerColor

像这个

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#00e0d1"
android:centerColor="#2fc1ea"
android:endColor="#C791F8"
android:angle="270"/>
<corners android:radius="30dp"/>
</shape>

之后如果你可以添加你的按钮背景

android:background

像这个

<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:background="@drawable/custom_bg"/>

最新更新