问题描述
我该怎么做?
解决方法
您可以简单地采用 Button
组件。但是如果你想拿 TextView
那么:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/start_btn_bg"
android:text="start"
android:paddingHorizontal="30dp"
android:paddingVertical="10dp"/>
您可以通过使自定义可绘制来设置背景。 以下是自定义可绘制对象:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="@color/color_red_error"
android:centerColor="@color/color_red_error"
android:endColor="@color/colorAccent"/>
<corners android:radius="20dp" />
,
如果你想要一个带有圆形文本视图的按钮,那么我就是这样做的。请注意,我在这里使用 com.google.android.material
以获得我想要的最快结果。
<com.google.android.material.button.MaterialButton
android:id="@+id/button"
android:backgroundTint="@android:color/holo_red_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="start"
app:cornerRadius="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
这就是它在我的 IDE 上的样子。