我想把纽扣的角弄圆。在Android中是否有一种简单的方法来实现这一点?


当前回答

图像

<androidx.cardview.widget.CardView
        android:id="@+id/add_coment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="15dp"
        android:clickable="true"
        android:foreground="?selectableItemBackground"
        android:outlineAmbientShadowColor="@color/blue_shadow_outline"
        app:cardCornerRadius="25dp"
        app:layout_constraintBottom_toBottomOf="@+id/coment"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/coment">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/btn_style2"
            android:fontFamily="@font/ar1"
            android:paddingHorizontal="10dp"
            android:text="text "
            android:textColor="@color/text_color"
            android:textSize="17dp" />
    </androidx.cardview.widget.CardView>

其他回答

图像

<androidx.cardview.widget.CardView
        android:id="@+id/add_coment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="15dp"
        android:clickable="true"
        android:foreground="?selectableItemBackground"
        android:outlineAmbientShadowColor="@color/blue_shadow_outline"
        app:cardCornerRadius="25dp"
        app:layout_constraintBottom_toBottomOf="@+id/coment"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/coment">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/btn_style2"
            android:fontFamily="@font/ar1"
            android:paddingHorizontal="10dp"
            android:text="text "
            android:textColor="@color/text_color"
            android:textSize="17dp" />
    </androidx.cardview.widget.CardView>

有一个app:cornerRadius属性用于普通的Button标签。

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:backgroundTint="#009688"
    android:onClick="xyz"
    android:paddingHorizontal="64dp"
    android:text="@string/login"
    app:cornerRadius="32dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/passwordCustom"
    app:layout_constraintVertical_bias="0.1" 
    />

在可绘制文件夹中创建一个xml文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">
    <!-- you can use any color you want I used here gray color-->
    <solid android:color="#ABABAB"/> 
    <corners android:radius="10dp"/>
</shape>

应用此作为背景按钮,你想使角圆润。

或者你可以使用单独的半径为每个角落,如下所示

android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"

可拉的文件夹

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FFFFFF"/>
    <corners android:radius="30dp"/>
    <stroke android:width="2dp" android:color="#999999"/>
</shape>

布局文件夹

<Button
    android:id="@+id/button2"
    <!-- add style to avoid square background -->
    style="@style/Widget.AppCompat.Button.Borderless"
    android:background="@drawable/corner_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

确保添加样式以避免方形背景

这个链接有你需要的所有信息。 在这里

Shape.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape      xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">

    <solid   android:color="#EAEAEA"/>

    <corners    android:bottomLeftRadius="8dip"
                android:topRightRadius="8dip"
                android:topLeftRadius="1dip"
                android:bottomRightRadius="1dip"
                />
</shape>

和main。xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">

    <TextView   android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Hello Android from NetBeans"/>

    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nishant Nair"
            android:padding="5dip"
            android:layout_gravity="center"
            android:background="@drawable/button_shape"
            />
</LinearLayout>

这应该会给你想要的结果。

祝你好运