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 8529587
In Process

The Archive Base Latest Questions

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

i want to make image button, so when it pressed i will replase the

  • 0

i want to make image button, so when it pressed i will replase the not-pressed image to pressed image of the button, and then go to other activity. i have two different images in drawable.

i have two xml files:

first one- load the main activity: background and image button

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="@android:color/black"
 android:orientation="vertical" >



<ImageButton
    android:id="@+id/b1_l"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/s1"
    android:scaleType="centerCrop"  
    android:background="@color/trans"

    android:src="@drawable/b1_l" />

</RelativeLayout>

second one:

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

   <item android:state_pressed="false"
   android:drawable="@drawable/image_not_pressed" />

   <item android:state_pressed="true"
   android:drawable="@drawable/image_pressed"" />

</selector>

what is the code that i need to write in addition to my xml?
or can i pass the xml and write it only as code…?

thanks!

  • 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-11T09:03:56+00:00Added an answer on June 11, 2026 at 9:03 am

    you need to usually have drawable for pressed and default(unpressed) state. You can have the xml file like this(below) for that. You need to put this xml file in the drawable folder and then use as src for ImageButton or background source in case of Button.

    Lets name it is mybutton.xml

    <?xml version="1.0" encoding="utf-8"?> 
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
        <item android:state_focused="true" android:state_pressed="true" 
                    android:drawable="@drawable/your image name" /> 
        <item android:state_focused="false" android:state_pressed="true" 
                    android:drawable="@drawable/your image name" /> 
        <item   android:drawable="@drawable/your image name" /> 
    </selector> 
    

    You layout file for main activity:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="@android:color/black"
     android:orientation="vertical" >
    
    
    
    <ImageButton
        android:id="@+id/b1_l"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/s1"
        android:scaleType="centerCrop"  
        android:background="@color/trans"
    
        android:src="@drawable/mybutton" />
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 4 image views on a view.I want to make the 4 images
I have an back button(Image Button) on the webview. I want to make this
I want make a carousel. But not a simple carousel with images. I have
I have an ImageButton: I want to make the image (circular play image) bigger.
I have can I make an Image button have focus while loading the page.
I have follow this post to make ImageButton in android android image button The
In my application i have an image button and two text boxes in a
I make a image into button control. Now i want to change that image
I have a button in my game. and I want to make it to
I want to make a simple image viewing program, that just takes the images

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.