Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable button with button selector

I have a button selector that changes the button image when it is pressed. I have also set an image for when the button is disabled. I try and disable the button programmatically but the disabled button image is not appearing. Is my button_selector correct?

<item android:drawable="@drawable/red_btn_bg_disabled" android:state_enabled="false"/> <!-- disabled -->

<item android:drawable="@drawable/red_btn_bg_pressed" android:state_pressed="true"/> <!-- pressed -->
<item android:drawable="@drawable/red_btn_bg_pressed" android:state_focused="true"/> <!-- focused -->

<item android:drawable="@drawable/red_btn_bg"/> <!-- default -->

I am using mButton.setEnabled(false) in my code to disable the button

like image 615
DMC Avatar asked Aug 29 '13 16:08

DMC


People also ask

How do you conditionally disable a button?

To conditionally disable a button element in Vue. js, you can dynamically bind the disable attribute to an expression that evaluates to boolean true (to disable the button) or false (to enable the button). Please note that :disable is a shorthand syntax for writing v-bind:disable .

How do I disable a button in CSS?

To make the disabled button, we will use the Pure CSS class “pure-button-disabled” with the class “pure-button”. We can also create a disabled button using disabled attribute. Disabled Button used Class: pure-button-disabled: It is used to disable the Pure CSS button.

How do I make a button not clickable?

To make a button non-clickable, you can enter: pointer-events: none; into the button module's "Button Settings > Advanced > Custom CSS > Main Element" box, like so: Note that this will also disable the hover effect on the button.


1 Answers

try this one and i uploaded one sample project for you for more help check the project

selector.xml

   <selector xmlns:android="http://schemas.android.com/apk/res/android">

        <item android:drawable="@drawable/btn_disable" android:state_enabled="false"/>
        <item android:drawable="@drawable/btn_pressed" android:state_pressed="true"/>
        <item android:drawable="@drawable/btn_normal"/>

    </selector>

and use this selector in button as following

<Button
         android:id="@+id/button1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/button1"
         android:layout_below="@+id/button1"
         android:layout_marginTop="30dp"
         android:background="@drawable/selector"
         android:enabled="false"
         android:text="Disable Button" />

sample code link https://www.dropbox.com/s/lydkog10rkujbsa/ButtonSelector.rar

like image 133
Likhit Jagatiya Avatar answered Sep 21 '22 15:09

Likhit Jagatiya