ImageButton 选择器不起作用

sag*_*lgy 5 android android-layout

我正在尝试为 ImageView 设置选择器,但它不起作用

我的布局

 <LinearLayout
        android:id="@+id/actionLayout"
        android:orientation="horizontal"
        android:background="@color/orange_color"
        android:gravity="center_vertical"
        android:paddingTop="@dimen/actions_top_bottom"
        android:paddingBottom="@dimen/actions_top_bottom"

        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="@dimen/actions_height"
            android:id="@+id/btnNoRecord"
            android:scaleType="centerInside"
            android:src="@drawable/ic_action_record"
            android:onClick="onRecordSwitcherClick"
            android:layout_weight="1"
            android:background="@drawable/selector"/>
...
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我的选择器.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/dark_orange_color"/>
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/orange_color"/>
        </shape>
    </item>
</selector>
Run Code Online (Sandbox Code Playgroud)

错误在哪里?也许在 LinearLayout 属性中存在一些错误?

编辑 我刚刚发现 LinearLayout 之外的 ImageButton 工作正常。但我真的需要布局

sag*_*lgy 1

我已经解决了!

在我的代码里面我有

btnNoRecord.setOnTouchListener(new View.OnTouchListener() {
   @Override
   public boolean onTouch(View view, MotionEvent motionEvent)
   {
       ...
       return true;
   }
});
Run Code Online (Sandbox Code Playgroud)

我将return true更改为return false并且它有效!