Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6371941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:09:42+00:00 2026-05-25T01:09:42+00:00

In Android, when I set a background image to a button, I can not

  • 0

In Android, when I set a background image to a button, I can not see any effect on it when it’s clicked.

I need to set some effect on the button, so the user can recognise that the button is clicked.

The button should be dark for a few seconds when it is clicked. How to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:09:43+00:00Added an answer on May 25, 2026 at 1:09 am

    This can be achieved by creating a drawable xml file containing a list of states for the button. So for example if you create a new xml file called "button.xml" with the following code:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/YOURIMAGE" />
        <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/gradient" />
        <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/gradient" />
        <item android:drawable="@drawable/YOURIMAGE" />
    </selector>
    

    To keep the background image with a darkened appearance on press, create a second xml file and call it gradient.xml with the following code:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item>
            <bitmap android:src="@drawable/YOURIMAGE"/>
        </item>
        <item>
            <shape xmlns:android="http://schemas.android.com/apk/res/android">
                <gradient android:angle="90" android:startColor="#880f0f10" android:centerColor="#880d0d0f" android:endColor="#885d5d5e"/>
            </shape>
        </item>
    </layer-list>
    

    In the xml of your button set the background to be the button xml e.g.

    android:background="@drawable/button"
    

    Changed the above code to show an image (YOURIMAGE) in the button as opposed to a block colour.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Android project, I've a image button whose background is set to some
I had a simple button set up with a background image defined like android:background=?attr/button
I set a background image to a layout via the android:background property. I want
I can set ImageButton background transparent in layout.xml using: android:background=@android:color/transparent How I can acomplish
In iOS, if I set a button's background to an image, when I press
In ImageButton I want to remove the standard button background image. In http://developer.android.com it
Is there any way to set the VideoView Background with image, so that when
I am trying to set up an Android emulator to do some playing around
Can we set Title for a Menu Item in Android if it has an
I am trying to set textColor property of button in android 2.1. But I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.