<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<solid android:color="#ABABAB"/>
<corners android:radius="10dp"/>
</shape>
10 回答
如果你想要这样的东西
这是代码 .
1.在mybutton.xml中的可绘制文件夹中创建一个xml文件并粘贴以下标记:
2.现在使用此drawable作为视图的背景 . 如果视图是按钮,那么这样的事情:
在drawable文件夹中创建一个xml文件,如下所示
将此作为背景应用于您想要使角落变圆的按钮 .
或者您可以为下面的每个角使用单独的半径
在drawable文件夹中创建shape.xml
像shape.xml
并在myactivity.xml中
您可以使用
这很简单 . 创建一个类似于下面的XML文件 . 将其设置为按钮的背景 . 如果您需要更多按钮曲线,请将radius属性更改为您的愿望 .
button_background.xml
Set background to your button:
我发现的简单方法是在drawable文件夹中创建一个新的xml文件,然后将按钮背景指向该xml文件 . 继承我使用的代码:
在Drawable文件夹中创建rounded_btn.xml文件...
并使用this.xml文件作为按钮背景
创建文件myButton.xml
添加到您的按钮
此链接包含您需要的所有信息 . Here
Shape.xml
和main.xml
这应该会给你你想要的结果 .
祝你好运
如果您使用矢量drawable,那么您只需在drawable定义中指定<corners>元素 . 我在blog post中报道了这一点 .
如果您使用的是bitmap / 9-patch drawables,那么您需要在位图图像中创建具有透明度的角 .
带图标的样式按钮
shape.xml