implement the iOS round button in Android
I am trying to create the iOS round button in Android. As you may know, Android buttons have grey background while the iOS round button has a clear background. I should use style开发者_运维知识库s and themes to achieve this.
However, I do not know how to piece things together. Could anyone please give some advice?
Thanks
No need for styles or themes. The trick with buttons on Android is to use a separate image for each state, and then combine them all with a selector xml. You can put something like this in your drawable directory and reference it like an image:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/btn_default_small_normal" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="@drawable/btn_default_small_normal_disable" />
<item android:state_pressed="true"
android:drawable="@drawable/btn_default_small_pressed" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/btn_default_small_selected" />
<item android:state_enabled="true"
android:drawable="@drawable/btn_default_small_normal" />
<item android:state_focused="true"
android:drawable="@drawable/btn_default_small_normal_disable_focused" />
<item
android:drawable="@drawable/btn_default_small_normal_disable" />
</selector>
Then just set the button background to this drawable. See State List for more information.
精彩评论