Android自定义的button按钮

<TextView 
        android:id="@+id/entry"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@drawable/shape_button_sure"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:gravity="center"
        android:text="@string/entry"
        android:textColor="@color/white"
        android:textSize="18sp" />
        />
    <Button 
        android:id="@+id/but"
        android:layout_width="match_parent"
        android:background="@color/sylan"
        android:layout_height="40dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:text="@string/entry"
        android:textColor="@color/white"
        android:textSize="18sp" />
        />

这样的两种按钮,显然textview自定义的要更好些

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners android:radius="5dp" />
    

    <solid android:color="#2678c4" />

   <padding
        android:bottom="5dp"
        android:left="20dp"
        android:right="20dp"
        android:top="5dp" />

</shape>

这是一个自定义的属性,但是好像padding并没有使用到,那么padding在哪个地方用到了

在一个item钟用到

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@drawable/shape_below"/>
   <item android:top="10px" android:right="10px" android:drawable="@drawable/shape_cover"/>
</layer-list>
 
原文地址:https://www.cnblogs.com/zhangyanguang/p/4912402.html