android - 为什么我不能让我的按钮变圆?
问题描述
我为我计划在登录屏幕中使用的自定义圆形按钮设计创建了一个名为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>
但是,按钮仍然是矩形的,即使我增加角大小,它也不会使边缘变圆
- 我做错了什么?
- 有没有更好的方法来构建我的 xml 文件以使按钮变圆?
解决方案
推荐阅读
- html - 我在 bootstrap 列中遇到 img 缩放问题
- node.js - 猫鼬删除错误的文件
- java - 遍历 HashMap 并将值放入 List
- javascript - 异步减少
- python-3.x - 如何在使用 boto3 创建 api-gateway 时添加命令“使用 Lambda 代理集成”
- java - 在测试中调用 SDOHelper.createRootDataObject 时的 NPE
- spring - 从之前的步骤获取xml配置spring批处理中的jobExecutionContext
- android - 如何在Android中将手机上的图像文件作为LiveData返回?
- java - 为什么我的代码不能返回我想要的?
- php - 如何在 laravel 中获得不同的查询结果?