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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:38:29+00:00 2026-06-17T08:38:29+00:00

I have a few ImageButtons in my app and I’v removed the default grey

  • 0

I have a few ImageButtons in my app and I’v removed the default grey background with

android:background="@android:color/transparent" or android:background="@null"

The problem is, it also removes the onClick highlight background (orange in API8 and blue in API16)

I’v read so many Q&A here, people are all suggesting to use selector.Instead of making another image for each of the buttons, I’d like to have a background color highlight only. Is there a simple way to achieve this?

solution: programmatically

import android.view.View;
import android.view.View.OnTouchListener;

// ...

btn.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == (MotionEvent.ACTION_DOWN)) {
            // set background highlight color
            btn.setBackgroundResource(R.color.blue);
        }
        if(event.getAction() == (MotionEvent.ACTION_UP)) {
            // restore transparent
            btn.setBackgroundResource(
                getResources().getColor(android.R.color.transparent));
        }
        return false;
    }
});

It isn’t that simple, but does the job and saves me a lot of time making another image for each button while I don’t really need fancy onclick styles.

  • 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-17T08:38:30+00:00Added an answer on June 17, 2026 at 8:38 am

    You really need to use a selector for this.

    You can use colors for your backgrounds in your selectors, it doesn’t need to be a PNG resource (just set the background to a color, instead of a drawable resource).

    You will place this code in your drawable folder, with a specific name (like button_sel.xml).

    Then you set this as the background to your button in your XML it would look like this:

    android:background="@drawable/button_sel"
    

    The selector would look something like this:

    <selector
        xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:drawable="@color/ab_background"
            android:state_focused="true"
            android:state_pressed="true"/>
        <item
            android:drawable="@color/ab_background"
            android:state_focused="false"
            android:state_pressed="true"/>
        <item
            android:drawable="@color/ab_background_on"
            android:state_focused="true"
            android:state_pressed="false"/>
        <item
            android:drawable="@color/ab_background_on"
            android:state_focused="false"
            android:state_pressed="false"/>
    </selector>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Android app, I have a few views (Buttons, EditTexts etc.) not visible
I have an iPhone app problem that's been bugging me for a few days
I have programatically created a set of ImageButton views (with transparent background) as map
I have an android app which uses google map and has a feature to
I have few questions about ssis transction isolation levels. consider a scenario:I have an
i have few confusion regarding ORM(Object Relational Mapping) i am thinking about to use
I have few basic questions on session management in GWTP. Now, we create a
I have few controls (Label, Custom Textbox, Datagridview) docked on a form. When I
I have few basic questions on session management in GWTP. Client : GWTP, Server
I have few text fields like SSN , phone number and email id. 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.