如何在Android中创建圆形轮廓的“材质按钮"? [英] How to create a circular outlined Material Button in Android?
本文介绍了如何在Android中创建圆形轮廓的“材质按钮"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个带有中心图标的按钮.圆的顶部和底部略微平坦.有没有一种方法可以不使用转角半径?这是我的按钮布局.
I am trying to create a button with an icon in the center. The top and bottom part of the circle are a little flat. Is there a way to do this without using corner radius? Here is my layout for the button.
<com.google.android.material.button.MaterialButton
android:id="@+id/start_dispenser_btn"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="175dp"
android:layout_height="175dp"
android:padding="14dp"
app:cornerRadius="150dp"
app:icon="@drawable/ic_play_arrow_black_60dp"
app:iconGravity="end"
app:iconSize="150dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/stop_dispenser_btn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/test_dispenser_container"
app:strokeColor="@color/background_black" />
推荐答案
您可以使用app:shapeAppearanceOverlay
属性来定义拐角大小.您可以使用50%
值.
You can use the app:shapeAppearanceOverlay
attribute to define the corner size. You can use the 50%
value.
<com.google.android.material.button.MaterialButton
android:layout_width="50dp"
android:layout_height="50dp"
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
app:icon="@drawable/ic_add_24px"
app:iconSize="24dp"
app:iconGravity="textStart"
android:padding="0dp"
app:iconPadding="0dp"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.MyApp.Button.Circle"
/>
具有:
<style name="ShapeAppearanceOverlay.MyApp.Button.Circle" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
或style="@style/Widget.MaterialComponents.Button.Icon"
它需要版本1.1.0.
It requires the version 1.1.0.
这篇关于如何在Android中创建圆形轮廓的“材质按钮"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文