首页 > 解决方案 > 为什么我不能让我的按钮变圆?

问题描述

我为我计划在登录屏幕中使用的自定义圆形按钮设计创建了一个名为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 文件以使按钮变圆?

标签: androidxmlbuttonrounded-cornersxml-drawable

解决方案


推荐阅读