总结

  1. Button
  2. MaterialButton
  3. CardView
  4. 三方库

conclusion:用 2

Button

写一个 drawable 文件

1
2
3
4
5
6
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="25dp"/>
<solid android:color="@color/material_dynamic_primary0"/>
</shape>

然后就可以直接用:

1
2
3
4
5
6
<!--Button + 自定义drawable文件-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me"
android:background="@drawable/my_button_background"/>

image-20230528122513200

大小控制在 drawable 文件哪里

MaterialButoon

1
2
3
4
5
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me"
app:cornerRadius="25dp"/>

image-20230528123122350

CardView

1
2
3
4
5
6
7
8
9
<androidx.cardview.widget.CardView
app:cardCornerRadius="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/click_me"/>
</androidx.cardview.widget.CardView>

image-20230528123141388

开源三方库

1
2
//圆角效果
implementation 'com.github.rey5137:material:1.2.5'
1
2
3
4
5
6
7
<com.rey.material.widget.Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me"
android:backgroundTint="@color/btn_filled_blue_bg_normal"
app:rc_cornerRadius="25dp" />

image-20230528123551381