自定义外观
自绘圆形背景
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
文档信息
- 本文作者:王玉镇wangyuzhen
- 本文链接:https://wangyuzhen666.github.io//wiki/android-view-button/
- 版权声明:Creative Commons 4.0 传播此文章时,您需要遵守知识共享协议。 署名(BY)&非商业性(NC)&相同方式共享(SA)------------------------------- When disseminating this article, you need to adhere to a Creative Commons license. Attribution (BY) & Non-Commercial (NC) & Shareby Manner (SA) .(Creative Commons 4.0)