Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Add Selector to the Button in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 431
    Comment on it

    Adding Button Selector to add button selector to the button in the android xlm layout file, create a new xml file named button selector and use the following code :

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@drawable/manage&#95;atms" android:state&#95;pressed="false" android:state&#95;selected="false"/>
        <item android:drawable="@drawable/manage&#95;atms&#95;mouseover" android:state&#95;pressed="true"/>
        <item android:drawable="@drawable/manage&#95;atms" android:state&#95;pressed="false" android:state&#95;selected="true"/>
    
    </selector>
    

    In the above code add the images to the item tag for pressed or not pressed button state. Then add this xml selector file to the background of the button. Example

    <Button
                    android:id="@+id/manage&#95;atms"
                    android:layout&#95;width="match&#95;parent"
                    android:layout&#95;height="60dp"
                    android:layout&#95;marginTop="10dp"
                    android:background="@drawable/manage&#95;atm&#95;button&#95;selector"
                    android:onClick="onClick" />
    

    Thank you, hope the code helps.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: