Note that there are some explanatory texts on larger screens.

plurals
  1. POSelector color on LinearLayout
    primarykey
    data
    text
    <p>I'm trying to assing a color selector to an extended class of LinearLayout, so, i think its like if we speak about linearLayout.</p> <p>i followed the instructions on <a href="https://stackoverflow.com/questions/3506319/android-linearlayout-with-color-resource-what-am-i-doing-wrong">this</a> post, the answer talking about shapes.</p> <p>Now i have 3 xml on drawables folders:</p> <p>normal.xml file</p> <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" &gt; &lt;solid android:color="#ffffffff" /&gt; &lt;/shape&gt; </code></pre> <p>pressed.xml file</p> <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" &gt; &lt;solid android:color="#00000000" /&gt; &lt;/shape&gt; </code></pre> <p>and finally, bg.xml file</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_pressed="true" android:drawable="@drawable/pressed" /&gt; &lt;item android:state_focused="true" android:drawable="@drawable/pressed" /&gt; &lt;item android:state_selected="true" android:drawable="@drawable/pressed" /&gt; &lt;item android:drawable="@drawable/normal" /&gt; &lt;/selector&gt; </code></pre> <p>I am accessing this in the following way:</p> <pre><code> Drawable d = getResources().getDrawable(context.getResources().getIdentifier("mypackageuri.tProject:drawable/bg", null, null)); view.setBackgroundDrawable(d); </code></pre> <p>The "normal" state its fine, with the color set at "normal.xml", but no way with the other ones, I press my view and nothing happens, it's not changing color in any way...</p> <p>I can't see what i'm doing wrong...</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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