Note that there are some explanatory texts on larger screens.

plurals
  1. POChange drawable color on button on click
    text
    copied!<p>I have some buttons with a text and a drawable set in the xml with <code>android:drawableLeft=...</code></p> <p>I want to know how to change, on click, the color of both the text and the drawable. And it has to be general, because i have a lot of button with each time, a different drawable.</p> <p>My XML :</p> <pre><code>&lt;LinearLayout android:id="@+id/linearLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:orientation="horizontal" &gt; &lt;Button android:id="@+id/btn_articles" style="@style/Main_button" android:layout_marginLeft="5dp" android:background="@color/green3" android:onClick="myClickHandler" android:text="Articles" android:drawableLeft="@drawable/ic_article" android:textColor="@drawable/btn_default" /&gt; &lt;Button android:id="@+id/btn_encaiss" style="@style/Main_button" android:layout_marginLeft="5dp" android:background="@color/green4" android:onClick="myClickHandler" android:text="Encaissement" android:drawableLeft="@drawable/ic_encaiss" android:textColor="@drawable/btn_default" /&gt; &lt;Button android:id="@+id/btn_stats" style="@style/Main_button" android:layout_marginLeft="5dp" android:background="@color/green1" android:onClick="myClickHandler" android:text="Statistiques" android:drawableLeft="@drawable/ic_stats" android:textColor="@drawable/btn_default" /&gt; &lt;Button android:id="@+id/btn_clients" style="@style/Main_button" android:layout_marginLeft="5dp" android:background="@color/green2" android:onClick="myClickHandler" android:text="Clients" android:drawableLeft="@drawable/ic_clients" android:textColor="@drawable/btn_default" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>For now i just change text color on click. I want to change both drawable and text color without knowing the left drawble name.</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