我想创建自定义按钮,我需要它是圆。我如何创建一个圆形按钮? 我认为使用draw9patch是不可能的。
我也不知道如何自定义按钮!
你有什么建议吗?
我想创建自定义按钮,我需要它是圆。我如何创建一个圆形按钮? 我认为使用draw9patch是不可能的。
我也不知道如何自定义按钮!
你有什么建议吗?
当前回答
Markushi写了一个具有惊人效果的圆圈按钮小部件。点击这里!
其他回答
对于MaterialButton上的FAB样式的按钮:
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
app:cornerRadius="28dp"
android:layout_width="56dp"
android:layout_height="56dp"
android:text="1" />
结果:
如果你改变大小,小心使用按钮大小的一半作为app:cornerRadius。
如果你想使用VectorDrawable和ConstraintLayout
<FrameLayout
android:id="@+id/ok_button"
android:layout_width="100dp"
android:layout_height="100dp"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:background="@drawable/circle_button">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/icon_of_button"
android:layout_width="32dp"
android:layout_height="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:srcCompat="@drawable/ic_thumbs_up"/>
<TextView
android:id="@+id/text_of_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/icon_of_button"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="5dp"
android:textColor="@android:color/white"
android:text="ok"
/>
</android.support.constraint.ConstraintLayout>
</FrameLayout>
圆圈背景:circle_button.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1000dp" />
<solid android:color="#41ba7a" />
<stroke
android:width="2dip"
android:color="#03ae3c" />
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
你可以从AndroidX材质库中使用MaterialButton
<com.google.android.material.button.MaterialButton
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_margin="10dp"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
app:cornerRadius="50dp"
app:icon="@drawable/ic_camera"
app:iconGravity="textStart"
app:iconPadding="0dp"
app:iconSize="35dp" />
就像这样
AngryTool自定义android按钮
你可以用这个工具网站制作任何类型的自定义android按钮… 我使圆形和方形按钮与圆角与这个工具站点.. 也许我能帮助你
Markushi写了一个具有惊人效果的圆圈按钮小部件。点击这里!