Note that there are some explanatory texts on larger screens.

plurals
  1. POLayerDrawable programmatically
    primarykey
    data
    text
    <p>Since my application's color theme is dynamic i can only create background drawables using colors and shapedrawables, i want to build a edittext background drawable with colors and shapes as shown below. But i want to do this programatically</p> <p>How to build this same drawable programatically?</p> <p></p> <pre><code>&lt;item&gt; &lt;shape&gt; &lt;solid android:color="@android:color/yellow" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;!-- main color --&gt; &lt;item android:bottom="1dp" android:left="1dp" android:right="1dp"&gt; &lt;shape&gt; &lt;solid android:color="@android:color/white" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;!-- draw another block to cut-off the left and right bars --&gt; &lt;item android:bottom="10dp"&gt; &lt;shape&gt; &lt;solid android:color="@android:color/white" /&gt; &lt;/shape&gt; &lt;/item&gt; </code></pre> <p></p> <p>this is what i tried....</p> <pre><code> GradientDrawable border = new GradientDrawable(); border.setShape(GradientDrawable.RECTANGLE); border.setColor(Color.WHITE); GradientDrawable background = new GradientDrawable(); background.setShape(GradientDrawable.RECTANGLE); background.setColor(Color.YELLOW); GradientDrawable clip = new GradientDrawable(); clip.setShape(GradientDrawable.RECTANGLE); border.setColor(Color.WHITE); Drawable[] layers = {background, border, clip}; LayerDrawable layerDrawable = new LayerDrawable(layers); layerDrawable.setLayerInset(0, 0, 0, 0, 0); layerDrawable.setLayerInset(1, 1, 0, 1, 1); layerDrawable.setLayerInset(2, 0, 0, 0, 10); </code></pre> <p>but the result is different....please help....!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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