Following the tips in a few other posts, I applied a round button that will be used in the application:

It is implemented using the XML selector:
<?xml version="1.0" encoding="utf-8" ?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/big_ring_button_unfocused" /> <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/big_ring_button_unfocused" /> <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/big_ring_button_focused" /> <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/big_ring_button_focused" /> <item android:state_pressed="true" android:drawable="@drawable/big_ring_button_pressed" /> </selector>
The contents ... of an unallocated file (the rest just change colors):
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring" android:innerRadius="@dimen/big_ring_button_inner_radius" android:thickness="@dimen/big_ring_button_thickness" android:useLevel="false"> <solid android:color="@color/white" /> </shape>
I would like to use this template for all rounded buttons in my application, but as the text inside the buttons changes, the size of the button itself must change.
I thought I could do it programmatically, so I checked the GradientDrawable documentation - there is no method for changing the innerRadius attribute.
I currently have 4 XML files for each round button (selector, unfocused, focused and pressed), which is extremely ugly and will become a pain in the neck to maintain.
How can I make this button customizable in size (either XML or programmatically)?
thanks
source share