答案 0 :(得分:2)
以下布局文件将产生一个半径为5px的按钮,当然你输入自己的颜色并将纯色更改为渐变以匹配你的截图,然后在按钮上将文本颜色改为白色或者其他东西..我不现在有时间举例......祝你好运。
最后你必须将它们作为按钮的背景应用于此
<Button
android:id="@+id/btnLoveThisOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Love me love u too!"
android:background="@drawable/button_background" <!-- Yes look at me -->
/>
button_background_normal.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/button_background_normal_color"/> <!-- Change this to your own colour -->
<corners android:radius="5px"/>
<stroke android:width="1dp" android:color="#20ffffff"/>
</shape>
button_background_pressed.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/button_background_pressed_color"/> <!-- Change this to your own colour -->
<corners android:radius="5px"/>
</shape>
button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/button_background_normal" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/button_background_pressed" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/button_background_pressed" />
<item android:drawable="@drawable/button_background_normal" />
</selector>
答案 1 :(得分:1)
我知道两种方法:
Button
或TextView
,图片有雕刻矩形,用于拉伸,使用9.patch :)。Button
或TextView
以及绘制形状边框的选择器但是,我不确切知道他们是如何做到的,如图所示。