为什么我的按钮无法四舍五入?

时间:2020-09-29 18:33:35

标签: android xml button rounded-corners xml-drawable

我已经创建了一个名为 rounded_button.xml xml 文件,用于计划在登录屏幕中使用的自定义圆形按钮设计。

这是我在xml文件中的代码

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/colorPrimaryDark"/>
    <corners
        android:topRightRadius="100px"
        android:topLeftRadius="100px"
        android:bottomRightRadius="100px"
        android:bottomLeftRadius="100px"
        />
</shape>

我试图像这样在登录屏幕中实现它

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    tools:context=".LoginActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Round"
        android:background="@drawable/round_button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

但是,按钮仍然是矩形,即使我增加了拐角的大小,它也不会使边缘变圆

  1. 我做错了什么?
  2. 是否有更好的方法来构造我的xml文件以使按钮变圆?

0 个答案:

没有答案