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 styles 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.