I had a button with a drawable selector set as its background.
button_sign_in_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_sign_in_background_selected" android:state_focused="true" />
<item android:drawable="@drawable/button_sign_in_background_selected" android:state_pressed="true" />
<item android:drawable="@drawable/button_sign_in_background_selected" android:state_selected="true" />
<item android:drawable="@drawable/button_sign_in_background_normal" />
</selector>
button_sign_in_background_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:visible="true">
<corners android:radius="@dimen/abc_control_corner_material" />
<solid android:color="@color/color_primary" />
</shape>
button_sign_background_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="@dimen/abc_control_corner_material" />
<solid android:color="@color/color_primary_dark" />
</shape>
I tested in two different devices, one with API 21 and another is API 10. The background button_sign_in_background.xml
can't show in API 10, but it works in API 21 device.
If I use color directly in button_sign_in_background.xml
as following, both devices work. But this is not the effect I need, what I want is a small radius corner surround the button.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/color_primary_dark" android:state_focused="true" />
<item android:drawable="@color/color_primary_dark" android:state_pressed="true" />
<item android:drawable="@color/color_primary_dark" android:state_selected="true" />
<item android:drawable="@color/color_primary" />
</selector>
Is that a compatibility problem in old android device?
How can i solve it? Any kind of comment and answer are welcomed.
I use the following code to solve the compatibility issue. Only tested with API level 10 (Android 2.3.3). After show the background drawable manually, it works fine. If there are more versions have this compatibility issue, comment will be welcomed.
If you want small radius corner button, below code has no problem from API 10 to Lollipop.
btn_done_background.xml
shape_round_normal.xml
shape_round_pressed.xml
A button to apply
I use
LinearLayout
as a button.