我想让button的角落变圆。 有没有一种简单的方法可以在Android中实现这一目标?
#1楼
在drawable文件夹中创建一个xml文件,如下所示
android:shape="rectangle" android:padding="10dp">
将此作为背景应用于您想要使角落变圆的按钮。
或者您可以为下面的每个角使用单独的半径
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
#2楼
如果你想要这样的东西
这是代码。
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" />