在java中如何创建一个默认圆_如何使按钮的角落圆?

我想让button的角落变圆。 有没有一种简单的方法可以在Android中实现这一目标?

#1楼

在drawable文件夹中创建一个xml文件,如下所示

android:shape="rectangle" android:padding="10dp">

将此作为背景应用于您想要使角落变圆的按钮。

或者您可以为下面的每个角使用单独的半径

android:bottomRightRadius="10dp"

android:bottomLeftRadius="10dp"

android:topLeftRadius="10dp"

android:topRightRadius="10dp"

#2楼

如果你想要这样的东西

9931d91ae8beb970e2e98e574f7f9fe3.png

这是代码。

1.在mybutton.xml中的可绘制文件夹中创建一个xml文件并粘贴以下标记:

2.现在使用此drawable作为视图的背景。 如果视图是按钮,那么这样的事情:

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="10dp"

android:textColor="#ffffff"

android:background="@drawable/mybutton"

android:text="Buttons" />

#3楼

在drawable文件夹中创建shape.xml

像shape.xml

android:color="#FFFFFF"/>

android:angle="225"

android:startColor="#DD2ECCFA"

android:endColor="#DD000000"/>

android:bottomLeftRadius="7dp"

android:bottomRightRadius="7dp"

android:topLeftRadius="7dp"

android:topRightRadius="7dp" />

并在myactivity.xml中

您可以使用

android:id="@+id/btn_Shap"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/Shape"

android:background="@drawable/shape"/>

#4楼

我发现的简单方法是在drawable文件夹中创建一个新的xml文件,然后将按钮背景指向该xml文件。 继承了我使用的代码:

#5楼

在Drawable文件夹中创建rounded_btn.xml文件...

android:color="@color/#000000"

/>

android:top="1dp"

android:right="1dp"

android:bottom="1dp"

/>

android:topLeftRadius="5dip" android:topRightRadius="5dip"/>

并使用this.xml文件作为按钮背景

android:id="@+id/btn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/rounded_btn"

android:text="Test" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值