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

  • SEARCH
  • Home
  • 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 8540875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:41:55+00:00 2026-06-11T11:41:55+00:00

How do I make an ImageButton image change its image when you press it?

  • 0

How do I make an ImageButton image change its image when you press it?

  • 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-06-11T11:41:56+00:00Added an answer on June 11, 2026 at 11:41 am

    I hope you find this helpful.

    This can all be done in the XML.

    1) Import your images for both pressed and unpressed states into the res/drawable-whichever folder

    2) Make your selectors. Right click on a drawable folder and select New/Android xml file. Put in the name eg “ok_button_selector.xml” and choose “selector” as the root element from the menu below. You will need to create a different selector for each button on the screen.

    3) In each selector file you need to define the image that will display when clicked, like this:

        <!-- language: lang-xml -->
        <?xml version="1.0" encoding="utf-8"?>
        <selector xmlns:android="http://schemas.android.com/apk/res/android" 
        >
        <item
            android:state_pressed = "true"
            android:drawable="@drawable/search_icon_pressed"/>
        <item
            android:drawable="@drawable/search_icon"/>
        </selector>
    

    They have to be in this order as the last is the default.

    4) In your layout file use the android:onClick=”myButtonClicked” method to define the buttons clicked behaviour. This saves having to use click listeners. Just make sure your java method has the same name 🙂

    5) Within the ImageButton tags define the attribute android:src=”@drawable/ok_button_selector” instead of the usual image file.

    Thats it! You don’t need any extra code in your java onClick method.

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

Sidebar

Related Questions

I have an ImageButton: I want to make the image (circular play image) bigger.
I have follow this post to make ImageButton in android android image button The
I want to make a simple ImageButton from an existing HTML markup: <input type=image
Im trying to make it so that on a press of a image button
I want to make an ad banner. Right now i have an imagebutton that
I make an app that have to printing image. I need to print image
If I was using an ImageButton with a selector for its background, is there
I'm trying to just make an activity that simply loads a random image when
I have this image for imagebutton, and i need to create patch 9 of
I have a imagebutton with a image source with transparency, but the background color

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.