Matheus Ariel
Matheus Ariel

Reputation: 105

Problems with setEnabled in imagebutton

I have ImageButton, putting setEnabled(false) that is so, but only in the emulator / tablet

enter image description here

But the button does not change anything when I put setEnabled(false) on some devices

some devices

Which can be? I would have all the appliances are as in the first image (I've tried using the android: clickable, but without success)

this is my xml:

 <LinearLayout
        android:id="@+id/MenuBotoes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#fc6719">

        <ImageButton
            android:id="@+id/btnMarcacao"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/draw"/>
        <ImageButton
            android:id="@+id/btnZoom"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/zoom"/>

        <ImageButton
            android:id="@+id/btnBorracha"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/eraser"/>
    </LinearLayout>

Upvotes: 1

Views: 223

Answers (1)

John Gallagher
John Gallagher

Reputation: 535

Setting the button as enabled or disabled will not necessarily change what it looks like, especially in the case of an imagebutton. You may need to make custom selectors/drawables/backgrounds for your images if you want to have different appearances based on state. You can do this by either changing the src or the background of your button to a selector drawable.

See selectors here: https://developer.android.com/guide/topics/resources/drawable-resource.html

And then see here: https://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html

Upvotes: 1

Related Questions