自定义外观
自绘圆形背景
layout/xxx.xml
<Button
...
android:background="@drawable/button_background"
/>
drawable/button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/shape_corners_pressed" />
<item android:drawable="@drawable/shape_corners" />
</selector>
drawable/shape_corners_pressed.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp"/>
<solid android:color="#22ffffff" />
<stroke android:color="@android:color/white" android:width="1dp" />
</shape>
drawable/shape_corners.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp"/>
<stroke android:color="@android:color/white" android:width="1dp" />
</shape>
去掉自带阴影
默认的按钮是带阴影的,可以通过设置 style="?android:attr/borderlessButtonStyle"
解决。
参考:https://developer.android.com/guide/topics/ui/controls/button.html#Borderless
文档信息
- 本文作者:Xiang Xisheng
- 本文链接:https://feieryun.github.io/wiki/android-view-button/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)