[英]Android radius button
I have a button like this 我有一个像这样的按钮
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerInParent="true"
android:text="ButtonText"
style="@style/ButtonText"/>
and this style 而这种风格
<style name="ButtonText">
<item name="android:layout_margin">3dp</item>
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">2</item>
</style>
Now I want to add radius to button, I have tried <item name="android:radius">6dp</item>
but it is not working. 现在,我想向按钮添加半径,我尝试了<item name="android:radius">6dp</item>
但是它不起作用。 What is a solution for this? 有什么解决方案?
In your drawable folder, create a round_button.xml with 在您的可绘制文件夹中,使用以下命令创建一个round_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://www.dibbus.com/2011/02/gradient-buttons-for-android/ -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<corners
android:radius="2dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
and then in the xml containing the button, set the background as: 然后在包含按钮的xml中,将背景设置为:
android:background="@drawable/round_button"
I believe to add radius to a button you have to create a custom drawable (see this link , specifically the shape drawable section) 我相信要向按钮添加半径,您必须创建自定义可绘制对象(请参阅此链接 ,特别是形状可绘制部分)
then, with the drawable defined, set the background
xml tag of the button equal to your drawable file: 然后,在定义了drawable的情况background
,将按钮的background
xml标记设置为等于您的drawable文件:
android:background="@drawable/your_file"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.