简体   繁体   English

如何更改 Material Design 3 中的按钮半径?

[英]How can I change the button radius in Material Design 3?

Google tells me I can change the button radius as you can see in the image below but not explain how谷歌告诉我我可以改变按钮半径,如下图所示,但没有解释如何

在此处输入图像描述

I want to change from rounded full (7) to rounded small (3) as you can see in the image below我想从圆形完整(7)更改为圆形小(3),如下图所示

在此处输入图像描述

Here is the button这是按钮

<com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:insetLeft="0dp"
        android:insetTop="0dp"
        android:insetRight="0dp"
        android:insetBottom="0dp"
        android:text="..." />

You need to use app:cornerRadius="10dp" property of MaterialButton to apply cornerRadius您需要使用MaterialButtonapp:cornerRadius="10dp"属性来应用cornerRadius

<com.google.android.material.button.MaterialButton
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:insetLeft="0dp"
  android:insetTop="0dp"
  android:insetRight="0dp"
  android:insetBottom="0dp"
  app:cornerRadius="10dp"
  android:text="..." />

and if you want cut in border-radius then please try this如果你想削减边界半径那么请试试这个

Create style like this创造这样的风格

<style name="ShapeAppearance.MyApp.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
    <item name="cornerFamily">cut</item>
    <item name="cornerSize">10dp</item> // change cornerSize as per your requiremnt 
 </style>

Then apply this style in your button like this然后像这样在按钮中应用这种样式

<com.google.android.material.button.MaterialButton
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintBottom_toBottomOf="parent"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:insetLeft="0dp"
      android:insetTop="0dp"
      android:insetRight="0dp"
      android:insetBottom="0dp"
      android:layout_margin="30dp"
      android:padding="30dp"
      app:shapeAppearanceOverlay="@style/ShapeAppearance.MyApp.SmallComponent"
      android:text="..."
      />

OUTPUT输出

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM