Android 圆形按钮实现

时间:2023-09-17 16:07:14

项目中用到的圆形按钮,做个半天,用sharp形式实现,样式代码如下:

<Button
android:id="@+id/btn_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/general_consulting"
android:textColor="@color/white"
android:textSize="@dimen/text_size18"
android:background="@drawable/bg_special_disease_circle"/>

其他不用在意,background bg_special_disease_circle.xml 样式代码如下:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item>
<shape android:shape="oval" >
<corners android:radius="@dimen/size90"/>
<solid android:color="@color/white" />
<size android:width="170dp" android:height="170dp"/>
</shape>
</item> <item android:bottom="8dp" android:right="8dp" android:top="8dp" android:left="8dp" >
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval" >
<corners android:radius="@dimen/size90"/>
<solid android:color="#e66b4f" />
<size android:width="162dp" android:height="162dp"/>
</shape>
</item> <item>
<shape android:shape="oval" >
<corners android:radius="@dimen/size90"/>
<solid android:color="#f3876f" />
<size android:width="162dp" android:height="162dp"/>
</shape>
</item> </selector>
</item> </layer-list>