我创建了一个这样的自定义按钮:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false" android:state_pressed="false">
<shape>
<gradient
android:endColor="@color/title_dark_red"
android:startColor="@color/title_red"
android:angle="270" />
<stroke
android:width="1dp"
android:color="@color/red_stroke" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="true" android:state_pressed="true">
<shape>
<gradient
android:endColor="@color/title_pressed_red"
android:startColor="@color/title_pressed_red"
android:angle="270" />
<stroke
android:width="1dp"
android:color="@color/red_stroke" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="false" android:state_pressed="true">
<shape>
<gradient
android:endColor="@color/title_pressed_red"
android:startColor="@color/title_pressed_red"
android:angle="270" />
<stroke
android:width="1dp"
android:color="@color/red_stroke" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
问题是按钮的灵敏度很差,不像普通的按钮。屏幕上的按钮并不算小,所以很容易触摸。
可能是什么问题?
PS 我正在使用 Button.OnClickListener() 来设置点击处理程序。
按钮是相对布局结构:
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
>
<TextView
android:id="@+id/titlePlace"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/expand_bg"
android:gravity="center_vertical"
android:text=""
android:textColor="@color/titletextcolor"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="@+id/backButton"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/showButton"
android:layout_alignBottom="@+id/showButton"
android:layout_alignParentLeft="true"
android:background="@drawable/custom_button_back"
android:layout_marginLeft="5dip"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="Places"
android:textColor="@color/white"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>