我想把纽扣的角弄圆。在Android中是否有一种简单的方法来实现这一点?
当前回答
有一个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"
/>
其他回答
在Drawable文件夹中创建rounded_btn.xml文件…
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/#FFFFFF"/>
<stroke android:width="1dp"
android:color="@color/#000000"
/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<corners android:bottomRightRadius="5dip" android:bottomLeftRadius="5dip"
android:topLeftRadius="5dip" android:topRightRadius="5dip"/>
</shape>
并使用this.xml文件作为按钮背景
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_btn"
android:text="Test" />
图像
<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>
带有图标的样式按钮
<Button
android:id="@+id/buttonVisaProgress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:background="@drawable/shape"
android:onClick="visaProgress"
android:drawableTop="@drawable/ic_1468863158_double_loop"
android:padding="10dp"
android:text="Visa Progress"
android:textColor="@android:color/white" />
shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="14dp" />
<gradient
android:angle="45"
android:centerColor="#1FA8D1"
android:centerX="35%"
android:endColor="#060d96"
android:startColor="#0e7e1d"
android:type="linear" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<size
android:width="270dp"
android:height="60dp" />
<stroke
android:width="3dp"
android:color="#000000" />
如果您使用的是矢量可绘制对象,那么您只需要在可绘制对象定义中指定一个<corners>元素。我在一篇博客文章中提到了这一点。
如果你使用位图/ 9-patch绘制,那么你需要在位图图像中创建透明的角落。
有一个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"
/>
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。