Android - Radio Button - button drawable not being displayed on Lollipop
Asked Answered
A

0

7

I'm writing an application for android 5 and above and in one screen I need to display a radio group with a couple of radio buttons, but the button drawable (xml drawable) is not showing on android 5 but is working as expected on android 6.

This is my activity layout:

<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@drawable/radio_button_selector"
        android:text="1" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@drawable/radio_button_selector"
        android:text="1" />

</RadioGroup>

radio_button_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="true" android:drawable="@drawable/radio_button_selected"  />
    <item android:drawable="@drawable/radio_button_unselected" />

</selector>

And radio_button_selected.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <size
        android:width="15dp"
        android:height="15dp" />

    <solid android:color="#643023" />

</shape>

And my activity:

public class Test extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
    }
}

I reproduced the problem on emulator API level 21 and on LG Leon 4G LTE (android 5, hdpi). The drawable is being displayed correctly on Nexus 5 (android 6.0.1, xxhdpi) and emulator with android 6.

All my resources are currently in default directories.

Alcott answered 5/5, 2016 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.