Disable an ImageButton

2019-02-01 20:02发布

This looks easy, but I'm not able to disable an ImageButton. It continues to receive click events, and its appearance don't change like a standard Button would.

There are some similar questions on SO, but they don't help me.

Even with a very simple layout like this :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <ImageButton
        android:id="@+id/btn_call"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:clickable="false"
        android:enabled="false"
        android:src="@android:drawable/sym_action_call" />

</LinearLayout>

The button is still enabled and I can click it.

What's strange is that if I change the ImageButton to a simple Button, then it works as expected. The button becomes disabled and unclickable. I don't understand. Does anyone have an idea?

7条回答
小情绪 Triste *
2楼-- · 2019-02-01 21:02

if you want to disable an image button,on click event, set the the property "setEnabled" to false

Ex: imgButton.setEnabled(false);

查看更多
登录 后发表回答