Android how to programmatically set Button stroke and radius
<p>I have this activity with 48 <code>Button</code> that the user can touch and change text and background color.</p>

<p><strong>I have edited the style of the default <code>Buttons</code> like this</strong>
<a href="https://i.stack.imgur.com/4FDki.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4FDki.png" alt="enter image description here"></a></p>

<p><strong>But when the user change the background color i have this bad result</strong></p>

<p><a href="https://i.stack.imgur.com/w4eLQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w4eLQ.png" alt="enter image description here"></a></p>

<p>These are the xmls that style the dafault <code>Buttons</code></p>

<p><strong>buttons.xml</strong></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:drawable="@drawable/button_pressed"
        android:state_pressed="true" /&gt;

    &lt;item android:drawable="@drawable/button_focused"
        android:state_focused="true" /&gt;

    &lt;item android:drawable="@drawable/button_default" /&gt;

&lt;/selector&gt;
</code></pre>

<p><strong>button_default.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" &gt;
    &lt;corners
        android:radius="100dp"
        /&gt;
    &lt;solid
        android:color="#FFFFFF"
        /&gt;
    &lt;padding
        android:left="0dp"
        android:top="0dp"
        android:right="0dp"
        android:bottom="0dp"
        /&gt;
    &lt;stroke
        android:width="3dp"
        android:color="#787878"
        /&gt;
&lt;/shape&gt;
</code></pre>

<p>In the other xml change only the color so i avoid to post them.
And here is the code that change the <code>Button</code>programmatically.
I take from <code>DB</code> all changed <code>Button</code> saved with <code>ID</code> and set the color of the <code>Button</code>.</p>

<pre><code>   //Get all materie inside database
    List&lt;Materia&gt; materia = db.getAllMaterie();
    //change all TextView inputed from user
    if(materia.isEmpty()){
        //do nothing
    }else {
        for (Materia mat : materia) {
            //Change all the Button with values stored inside the database
            int resId = getResources().getIdentifier(mat.getID(), "id", getPackageName());
            final Button changedButton = (Button) findViewById(resId);
            changedButton.setText(mat.getMateria());
            changedButton.setTypeface(null, Typeface.BOLD);
            changedButton.setBackgroundColor(mat.getColor());

        }
    }
</code></pre>

<p>But i lose the radius and stroke property.
There is some way to set them programmatically?
<strong>Other suggestions are accepted!</strong></p>