自定义button样式
时间: 2023-11-11 08:07:03 浏览: 75
如果你想自定义一个Button的样式,可以通过创建一个drawable资源文件来实现,具体步骤如下:
1. 在res目录下的drawable文件夹中创建一个新的xml文件,比如说button_custom.xml。
2. 在button_custom.xml文件中定义一个shape,可以设置Button的背景颜色、边框等属性。
例如:
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF4081" />
<corners android:radius="8dp" />
<stroke
android:width="1dp"
android:color="#FF4081" />
</shape>
```
3. 在Button的布局文件中,将Button的background属性设置为button_custom.xml文件即可。
例如:
```xml
<Button
android:id="@+id/btn_custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Button"
android:background="@drawable/button_custom" />
```
这样就可以自定义一个Button的样式了。你也可以通过修改button_custom.xml文件中的属性来实现其他样式。
阅读全文
相关推荐

















