Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Problem whie TextView background color change on the different state of it
    text
    copied!<p>Please Try the below code and guide me, my problem is that <strong>i am not getting the "Pressed" state for the TextView</strong>, is it possible to implement Pressed state for the TextView? how do i? </p> <p>I am having a success using the below code for the Button but not having success for the TextView.</p> <p>pls guide me</p> <p>My Button and TextView code:</p> <pre><code>&lt;Button android:id="@+id/Button01" android:layout_width="fill_parent" android:layout_height="50dp" android:background="@drawable/button_state" android:padding="20dp"&gt; &lt;/Button&gt; &lt;TextView android:text="Demo of Color on state change" android:id="@+id/TextView01" android:layout_width="fill_parent" android:layout_height="50dp" android:background="@drawable/button_state" android:focusable="true"&gt; &lt;/TextView&gt; </code></pre> <p><strong><code>button_state.xml</code></strong> file (I have stored it in drawable folder):</p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true"&gt; &lt;shape&gt; &lt;gradient android:startColor="@color/yellow1" android:endColor="@color/yellow2" android:angle="270" /&gt; &lt;stroke android:width="3dp" android:color="@color/grey" /&gt; &lt;corners android:radius="3dp" /&gt; &lt;padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;item android:state_focused="true" &gt; &lt;shape&gt; &lt;gradient android:endColor="@color/orange1" android:startColor="@color/orange2" android:angle="270" /&gt; &lt;stroke android:width="3dp" android:color="@color/grey" /&gt; &lt;corners android:radius="3dp" /&gt; &lt;padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;item&gt; &lt;shape&gt; &lt;gradient android:endColor="@color/blue1" android:startColor="@color/blue2" android:angle="270" /&gt; &lt;stroke android:width="3dp" android:color="@color/grey" /&gt; &lt;corners android:radius="3dp" /&gt; &lt;padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;/selector&gt; </code></pre> <p><strong><code>color.xml</code></strong> file:</p> <pre><code>&lt;resources&gt; &lt;color name="yellow1"&gt;#FFFF99&lt;/color&gt; &lt;color name="yellow2"&gt;#FFCC00&lt;/color&gt; &lt;color name="orange1"&gt;#FF9966&lt;/color&gt; &lt;color name="orange2"&gt;#FF6600&lt;/color&gt; &lt;color name="blue1"&gt;#99CCFF&lt;/color&gt; &lt;color name="blue2"&gt;#0033CC&lt;/color&gt; &lt;color name="grey"&gt;#736F6E&lt;/color&gt; &lt;/resources&gt; </code></pre>
 

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