Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Relative Layout Selector
    text
    copied!<p>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.</p> <p>This is the code i used.</p> <pre><code> &lt;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" &gt; &lt;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" /&gt; &lt;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" /&gt; &lt;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" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>relative_selector.xml In here I'm doing the changes using selector.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_focused="true" android:drawable="@drawable/relative_focus"/&gt; &lt;item android:state_pressed="true" android:state_enabled="false" android:drawable="@drawable/relative_clicked" /&gt; &lt;item android:drawable="@drawable/relative_background"/&gt; &lt;/selector&gt; </code></pre> <p>relative_background.xml This is the shape.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:padding="10dp" android:shape="rectangle"&gt; &lt;stroke android:width="1dp" android:color="#636161" /&gt; &lt;padding android:left="5dp" android:top="2dp" android:right="2dp" android:bottom="5dp" /&gt; &lt;corners android:radius="6dp" /&gt; &lt;solid android:color="#88ffffff" /&gt; &lt;/shape&gt; </code></pre> <p>In "relative_clicked.xml" and "relative_focus.xml" I only changed the colors.</p> <p>relative_focus.xml</p> <pre><code> &lt;stroke android:width="1dp" android:color="#ffff00" /&gt; </code></pre> <p>relative_clicked.xml</p> <pre><code> &lt;solid android:color="#88ffff00"/&gt; </code></pre> <p>All .xml files are in drawable folder. I want to work this like a button.Is someone having any idea?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload