自定义圆角button
自定义圆角Button,需两步:
1.在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="#FFFFFF" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="5dip" />
<!-- padding:Button里面的文字与Button边界的间隔 -->
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"
/>
</shape>
2.在Activity的xml文件中将Button背景设置成刚刚创建的文件的背景。
示例:
<!--main_activity.xml-->
<Button
android:id="@+id/roundButton"
android:text=" 圆角按钮 "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_shape"
/>
自定义圆形button
示例:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#B40404"/>
<corners android:radius="360dip"/>
</shape>