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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:53:29+00:00 2026-06-02T20:53:29+00:00

How do I change the color of a Relative Layout Shape ? To work

  • 0

How do I change the color of a Relative Layout Shape ? To work it like a button.
I tried to do it using a selector.

This is the code i used.

       <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/rlGPS"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:background="@drawable/relative_selector"

            >

            <ImageView
                android:id="@+id/iv1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:id="@+id/tvs1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="5dp"
                android:layout_below="@+id/tvl1"
                android:layout_toLeftOf="@+id/iv1"
                android:text="you can here protect ... "
                android:textColor="@color/gray" />

            <TextView
                android:id="@+id/tvl1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_toLeftOf="@id/iv1"
                android:text="GPS"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="@color/white" />
        </RelativeLayout>

relative_selector.xml In here I’m doing the changes using selector.

<?xml version="1.0" encoding="utf-8"?> 

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


  <item android:state_focused="true" android:drawable="@drawable/relative_focus"/>
  <item android:state_pressed="true" android:state_enabled="false"
   android:drawable="@drawable/relative_clicked" />
  <item android:drawable="@drawable/relative_background"/>

</selector>

relative_background.xml This is the shape.

<?xml version="1.0" encoding="utf-8"?>


<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:padding="10dp"
 android:shape="rectangle">

 <stroke android:width="1dp" android:color="#636161" />

 <padding android:left="5dp"
    android:top="2dp"
    android:right="2dp"
    android:bottom="5dp" />

 <corners android:radius="6dp" />

 <solid android:color="#88ffffff"
     />

</shape>

In “relative_clicked.xml” and “relative_focus.xml” I only changed the colors.

relative_focus.xml

      <stroke android:width="1dp" android:color="#ffff00" /> 

relative_clicked.xml

      <solid android:color="#88ffff00"/> 

All .xml files are in drawable folder.
I want to work this like a button.Is someone having any idea?

  • 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-02T20:53:31+00:00Added an answer on June 2, 2026 at 8:53 pm

    From your selector xml:

    <item android:state_pressed="true" 
          android:state_enabled="false" 
          android:drawable="@drawable/relative_clicked" />
    

    Will it work if you remove state_enabled?

    <item android:state_pressed="true" 
          android:drawable="@drawable/relative_clicked" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am try to change relative layout background color like blink first set green
I want to change color of h3 links to red in this code: <div
Please i need to change color of a single character in textarea using JQuery.
i need change color of SystemTray.ProgressIndicator color, how i can do it? I tried
Im using http://phase-change.org/jquery.gridlayout to achieve the fluid layout of several divs in my layout.
I have a layout like this in which I want to display a label
I'm trying to change the TabWidget text color, without success, even though I've tried
I want to change color of the UINavigationBar? Is it possible to keep different
I want to change color of ListView separator line.
How to change color of selected ListPicker Item in Full Mode? What style need

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.