Following suggestions in few other posts, I implemented a circular button to be used in the app:
It is implemented using XML selector:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://ift.tt/nIICcg">
<!-- Non focused states
-->
<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" />
<!-- Focused states
-->
<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" />
<!-- Pressed
-->
<item android:state_pressed="true" android:drawable="@drawable/big_ring_button_pressed" />
</selector>
The contents of the ..._unfocused file (the others just change colors):
<shape
xmlns:android="http://ift.tt/nIICcg"
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'd like to use this template for all rounded buttons in my app, but since the text inside the buttons change, the size of the button itself should change.
I thought that I might be able to accomplish this programmatically, so I checked the documentation of GradientDrawable - there is no method there to change innerRadius
attribute.
Currently I have 4 XML files per each round button (selector, unfocused, focused and pressed) which is extremely ugly and will become a pain in the neck to maintain.
How could I make this button configurable in size (either XML or programmatically)?
Thanks
No comments:
Post a Comment