title: How to make a circular drawable with stroke, programmatically?
body: <h2>Background</h2>
  
  <p>I'm trying to have a filled circle, with a stroke of certain color and width, and an image inside.</p>
  
  <p>This can easily be done in XML, as such (this is just a sample) :</p>
  
  <pre><code>&lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item&gt;
          &lt;shape android:shape="oval"&gt;
              &lt;size
                  android:width="120dp" android:height="120dp"/&gt;
              &lt;solid android:color="#ffff0000"/&gt;
              &lt;stroke
                  android:width="3dp" android:color="#ff00ff00"/&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
      &lt;item
          android:width="60dp" android:height="60dp" android:drawable="@android:drawable/btn_star"
          android:gravity="center"/&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/bAjGa.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bAjGa.png" alt="enter image description here"></a></p>
  
  <h2>The problem</h2>
  
  <p>I need to have certain properties of the above to change programmatically, so I can't use the XML file, but the idea is still the same.</p>
  
  <p>Thing is, I can't find an easy way to put a stroke on an OvalShape drawable, as done in XML. I can't find the function to do it.</p>
  
  <h2>What I tried</h2>
  
  <p>There are solutions out there here on StackOverflow, but I couldn't find one that works well. Only one I've found is <a href="https://stackoverflow.com/a/3663956/878126"><strong>here</strong></a>, but its stroke line is being cut .</p>
  
  <p>I have, however, partially succeeded in one way to solve this, by using an XML just for the stroke itself:</p>
  
  <p>stroke_drawable.xml</p>
  
  <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"&gt;
      &lt;stroke
          android:width="4dp" android:color="@android:color/white"/&gt;
  &lt;/shape&gt;
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>    final int strokeDrawableResId = R.drawable.stroke_drawable;
      Drawable innerDrawable = ResourcesCompat.getDrawable(getResources(), ..., null);
      final Drawable strokeDrawable = ResourcesCompat.getDrawable(getResources(), strokeDrawableResId, null);
      ShapeDrawable biggerCircle = new ShapeDrawable(new OvalShape());
      int size = ...;
      biggerCircle.setIntrinsicHeight(size);
      biggerCircle.setIntrinsicWidth(size);
      biggerCircle.getPaint().setColor(0xffff0000);
      biggerCircle.setBounds(new Rect(0, 0, size, size));
      LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{biggerCircle, strokeDrawable, innerDrawable});
  
      ImageView imageView = findViewById(R.id.imageView);
      imageView.setImageDrawable(layerDrawable);
  </code></pre>
  
  <p>It works, but it's not fully programmatically (stroke is defined in XML). </p>
  
  <h2>The question</h2>
  
  <p>How to change the code to be fully programmatic ? </p>
  
  <hr>
  
  <p>EDIT: I tried what was suggested here, yet instead of an additional drawable for a background, since I needed it all in one drawable, I used LayerDrawable:</p>
  
  <pre><code>    Drawable innerDrawable = ResourcesCompat.getDrawable(getResources(), android.R.drawable.btn_star, null);
      int strokeWidth = 5;
      int strokeColor = Color.parseColor("#ff0000ff");
      int fillColor = Color.parseColor("#ffff0000");
      GradientDrawable gD = new GradientDrawable();
      gD.setColor(fillColor);
      gD.setShape(GradientDrawable.OVAL);
      gD.setStroke(strokeWidth, strokeColor);
      LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{gD, innerDrawable});
      ImageView imageView = findViewById(R.id.imageView);
      imageView.setImageDrawable(layerDrawable);
  </code></pre>
  
  <p>This works, but for some reason the drawable inside (the star) is being stretched:</p>
  
  <p><a href="https://i.stack.imgur.com/uYMjH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/uYMjH.png" alt="enter image description here"></a></p>