title: Android Draw on top of an EditText, Spinner or Button (Draw on Screen)
body: <p>what I want to achieve is this:</p>
  
  <p><img src="https://i.stack.imgur.com/0NDJg.jpg" alt="enter image description here"></p>
  
  <p>As you can see there is are two tiny, yellow triangles (warning signs) in the EdiTtexts. I read, it's possible to achieve that by using Relative layout and simply have the images overlap the EditText. This however is not an option as I am writing a library project and can't limit the user to one particular layout type (such as RelativeLayout). Alternatively I read, it can be done in the onDraw method of a view. However, I will have no access to the onDraw method (or rather now way of overriding it). The one thing I have access to, is the Views itslef (like Spinner, EditText) or alternatively their wrapping view (Like LinearLayout etc...). I need to set this tiny icon not only on EditText but generally on Views such as Spinner, Button, EditText, etc....</p>
  
  <p>One idea was to simply obtain the x/y coordinates of the View on which I want to draw that warning sign, but although I am able to get the coordinates I am quite at a loss as to how to actually do the drawing on the obtained view.</p>
  
  <p>On an additional note: I am using code to generate the layout from non-android layout-xml files. That only matters in so far, that I am afraid android-layout-xml-based solutions are not an option. Furthermore I have to be able to dynamically add/remove those image overlays.</p>
  
  <p>Please let me know, if there are further questions.</p>
  
  <p>Thank you very much in advance &amp; Best regards,
  Ready4Android</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I had one idea but I am not sure how to carry it out: I could determine the on-screen coordinates of my Widgets (like Spinner, EditText, Button...) and then I could draw that little warning symbol on top of my canvas - without even touching the Widgets. So would it be easier to solve, if I just wanted to draw on the screen? It should be possible, non?</p>
  
  <p><strong>EDIT 2</strong> (20.09)</p>
  
  <p>I followed the advice from superM but since the Icon was stretched I tried to use a bitmap inside the item. Thing is: It places the icon at the correct place (left edge) but the skin of the button disappears - I guess because it's replaced by the bitmap...</p>
  
  <p>Here is the original Button:</p>
  
  <p><img src="https://i.stack.imgur.com/naifd.png" alt="enter image description here"></p>
  
  <p>Here the Xml (the invisible shape is the same as in superM's post):</p>
  
  <pre><code>&lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:drawable="@drawable/sign_warning_overlay_shape"
          android:top="5dip" android:right="5dip" android:bottom="5dip"
          android:left="5dip" /&gt;
      &lt;item&gt;
          &lt;bitmap android:src="@drawable/sign_warning" android:gravity="left" /&gt;
      &lt;/item&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p>and this is how it looks:</p>
  
  <p><img src="https://i.stack.imgur.com/nro6F.png" alt="enter image description here"></p>
  
  <p>With the original posted layer list by superM - this one:</p>
  
  <pre><code>&lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:drawable="@drawable/sign_warning_overlay_shape"
          android:top="5dip" android:right="5dip" android:bottom="5dip"
          android:left="5dip" /&gt;
      &lt;item android:drawable="@drawable/sign_warning" android:top="5dip"
          android:right="5dip" android:bottom="5dip" android:left="5dip" /&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p>the Button looks like this(seems like here too the icon replaces the button skin):</p>
  
  <p><img src="https://i.stack.imgur.com/YXBlx.png" alt="enter image description here"></p>
  
  <p>Could it be, that I am setting the layer list in a wrong way? What would be the correct code to set the layer list on a button? I am using this one:</p>
  
  <pre><code>button.setBackgroundResource(R.drawable.sign_warning_overlay_layer_list);
  </code></pre>
  
  <p><strong>Edit 3 - Modified solution</strong></p>
  
  <p>This edit is based on the accepted answer - I decided to go for a bitmap embedded in an item because I had issues with the image being stretched - here is the layer_list:</p>
  
  <pre><code>&lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:drawable="@android:drawable/btn_default"
          android:top="5dip" android:right="5dip" android:bottom="5dip"
          android:left="5dip" /&gt;
      &lt;item&gt;
          &lt;bitmap android:src="@drawable/sign_warning" android:gravity="left" /&gt;
      &lt;/item&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p>Which can be set on the button like this:
      button.setBackgroundDrawable(button.getResources().getDrawable(                 R.drawable.layer_list));</p>
  
  <p>and produces the following result:</p>
  
  <p><img src="https://i.stack.imgur.com/uk5Ws.png" alt="enter image description here"></p>
  
  <p>That's it folks :) !</p>
  
  <p>Thanks for all the suggestions &amp; Cheers,</p>
  
  <p>Ready4Android</p>