在res目录下的drawable目录下新建button_shape.xml文件
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> android:shape="rectangle"> <!-- 填充的颜色 --> <solid android:color="#2eb12a" /> <!-- 设置按钮的四个角为弧形 --> <!-- android:radius 弧形的半径 --> <corners android:radius="6dip" /> <!-- padding:Button里面的文字与Button边界的间隔 --> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape>
在布局文件中调用button_shape
<Button android:id="@+id/bLogin" android:layout_width="match_parent" android:layout_marginBottom="10dp" android:layout_height="wrap_content" android:background="@drawable/button_shape" android:textColor="#f5f0f0" android:text="登陆" />
界面效果