1. 先上代码

这里我自己定义了一个drawable文件

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/goCart_btn"/>
    <corners android:topLeftRadius="25dp" android:bottomLeftRadius="25dp"/>
</shape>

在按钮通过设置background属性来使用,如下:

<LinearLayout
            android:gravity="center"
            android:layout_weight="4.0"
            android:layout_width="0dp"
            android:layout_height="wrap_content">
            <Button
                android:textColor="@color/white"
                android:textSize="12dp"
                android:background="@drawable/gocart_btn"
                android:text="加入购物车"
                android:layout_weight="1.0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <Button
                android:textSize="12dp"
                android:textColor="@color/white"
                android:text="立即购买"
                android:background="@drawable/gobuy_btn"
                android:layout_weight="1.0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </LinearLayout>

结果,显示的效果与我想要的不一样,确切的说,它根本就不生效,总是显示默认的紫蓝色,如下:
在这里插入图片描述

最后,花了点时间,终于找到原因了

2.解决方法

在res/values/themes.xml中
在这里插入图片描述
修改为
在这里插入图片描述

3.最后效果

完美解决,开心
在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐