android中的白色按钮的可点击效果

时间:2013-10-25 13:32:06

标签: android

我对其他颜色按钮进行了可点击效果但是如何为白色按钮生成可点击效果

<Button
            android:id="@+id/featured_listing_button_id"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="-7dp"
            android:background="@drawable/botton_account_middle_white"
            android:text="Featured Listing" />

我尝试了什么 ::我已将按钮设为白色,其他一些属性

但现在不存在可点击效果!

botton_account_middle_white.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#FFFFFF" />

    <stroke
        android:width="3px"
        android:color="#000000" />

    <corners android:radius="3dp" />

    <padding
        android:bottom="10dp"
        android:left="10dp"
        android:right="10dp"
        android:top="10dp" />



    <corners
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="0dp"
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp" />

</shape>

如何为按钮提供可点击的效果! ...白色按钮

2 个答案:

答案 0 :(得分:0)

您应该使用选择器突出显示按钮。

button_selector.xml

 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
         <item 
     android:state_selected="false"
        android:state_pressed="false" 
        android:color="@color/normal" />
    <item android:state_pressed="true" 
        android:color="@color/pressed" />
    <item android:state_selected="true"
     android:state_pressed="false" 
        android:color="@color/pressed" />
</selector>

一样使用它
<Button
            android:id="@+id/featured_listing_button_id"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="-7dp"
            android:background="@drawable/button_selector"
            android:text="Featured Listing" />

答案 1 :(得分:0)

<?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="true" 
            android:drawable="@drawable/bgalt" /> 
      <item android:state_focused="false" android:state_pressed="true" 
            android:drawable="@drawable/bgalt" /> 
      <item android:drawable="@drawable/bgnorm" /> 
  </selector>
<Button
  android:id="@+id/mybutton"
  android:background="@drawable/selector" />