如何制作像标题按钮这样的“Gmail”? (附图片)

时间:2011-10-09 14:29:16

标签: android

有没有人知道我如何将Android按钮设置为这样:

a busy cat http://www.11sheep.com/temp/picForSO.jpg

提前致谢, 利奥尔

2 个答案:

答案 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)

我知道两种方法:

  1. a ButtonTextView,图片有雕刻矩形,用于拉伸,使用9.patch :)。
  2. 具有透明背景的ButtonTextView以及绘制形状边框的选择器
  3. 但是,我不确切知道他们是如何做到的,如图所示。