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

The Archive Base Latest Questions

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

I have an ImageView with both image src and background color set. This image

  • 0

I have an ImageView with both image src and background color set.

This image is into a layout that is the gridview item layout.

I would to create an xml selector that when the item is choosen, the image background change, but the image src not.

Something similar to the main menu of android with icon with text, I want to highlight only the image.

I would not to make an image for each state of the object, I only want to change the background.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/img_0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:background="@drawable/selector_categorie"
        android:src="@drawable/ic_launcher"/>

    <TextView
        android:id="@+id/text_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/img_0"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/text_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text_1"
        android:layout_marginTop="15dp"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/text_3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text_2"
        android:layout_marginTop="15dp"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceMedium" />


</RelativeLayout>
  • 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-17T06:53:39+00:00Added an answer on June 17, 2026 at 6:53 am

    This can be achieved with a StateListDrawable.

    Create a background drawable resource, e.g. item_background.xml, in your /drawable folder, containing something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:drawable="@color/color1" android:state_pressed="true"/>
      <item android:drawable="@color/color2" android:state_selected="true"/>
      <item android:drawable="@color/color3" android:state_activated="true"/>
      <item android:drawable="@color/color4"/>
    </selector>
    

    Then provide the color values in your /values/colors.xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <color name="color1">#DDff8800</color>
      <color name="color2">...</color>
      <!-- more colors... -->
    </resources>
    

    Finally, set that drawable resource as the item background in your layout with android:background="@drawable/item_background".

    The src image remains untouched.

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

Sidebar

Related Questions

If i have an ImageView that fills the screen. The ImageView background is set
I have this layout and I would like the image to span across 2
I have imageView in activity. How I can set position this imageView in my
I have this ImageView in my layout: <ImageView android:layout_width=fill_parent android:layout_height=wrap_content android:contentDescription=@string/image_divider android:paddingBottom=8dp android:paddingTop=4dp android:scaleType=fitXY
Background: I have an ImageView that I've modified to be scrollable (drag) and zoom-able
I have a large header image that I'd like to use for both tablet
I have this ImageView block inside a Relative layout: <ImageView android:layout_width=wrap_content android:layout_height=wrap_content android:layout_alignParentBottom=true android:layout_marginBottom=50dip
I have imageView inside a relative layout. And when i create the activity i
I have an ImageView in my activity that shows an active symbol when a
I have a ImageView and draw some things on that view. Now I want

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.