Селектор фона кнопки не отображается - PullRequest
0 голосов
/ 06 марта 2019

Я пытаюсь присвоить селектору значение RadioButton из android:button, но не могу отобразить эту кнопку в предварительном просмотре, а также реальное устройство. Моя цель состоит в том, чтобы сделать android:button пользовательским.Я должен RadioGroup с двумя RadioButton.Я пробовал это решение также https://stackoverflow.com/a/12432722/6869491 Но все еще не смог получить желаемое решение.

<RadioGroup
            android:id="@+id/radio_group"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/padding_25"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="@id/sub_const"
            app:layout_constraintEnd_toEndOf="@id/sub_const"
            app:layout_constraintStart_toStartOf="@id/sub_const"
            app:layout_constraintTop_toBottomOf="@id/pay_amt_et">


            <RadioButton
                style="@style/MyRadioButtonStyle"
                android:id="@+id/manual_rb"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:checked="true"
                android:text="@string/manual"
                android:textColor="@color/textcolor"
                android:textSize="@dimen/fontsize_16"
                />

            <RadioButton
                style="@style/MyRadioButtonStyle"
                android:id="@+id/recurring_rb"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Recuring"
                android:textColor="@color/textcolor"
                android:textSize="@dimen/fontsize_16"
             />
         </RadioGroup>

А вот селектор переключателей, то есть radio_btn_selector.

<item android:state_checked="true" android:state_window_focused="false"
    android:drawable="@drawable/radio_btn_active" />
<item android:state_checked="false" android:state_window_focused="false"
    android:drawable="@drawable/radio_btn_un_selected" />

<item android:state_checked="true" android:state_pressed="true"
    android:drawable="@drawable/radio_btn_active" />
<item android:state_checked="false" android:state_pressed="true"
    android:drawable="@drawable/radio_btn_un_selected" />

<item android:state_checked="true" android:state_focused="true"
    android:drawable="@drawable/radio_btn_active" />
<item android:state_checked="false" android:state_focused="true"
    android:drawable="@drawable/radio_btn_un_selected" />

<item android:state_checked="false" android:drawable="@drawable/radio_btn_un_selected" />
<item android:state_checked="true" android:drawable="@drawable/radio_btn_active" />

А вот radio_btn_active.

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

        <item>

            <shape android:shape="oval">
                <solid android:color="@color/colorWhite" />

                <stroke
                    android:width="@dimen/padding_2"
                    android:color="@color/grey_darker" />

            </shape>
        </item>

        <item
            android:bottom="@dimen/padding_30"
            android:end="@dimen/padding_30"
            android:start="@dimen/padding_30"
            android:top="@dimen/padding_30">

            <shape android:shape="oval">
                <solid android:color="@color/primary_edtext_light" />


            </shape>
        </item>
    </layer-list>

И это radio_btn_un_selected.

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

    <stroke
        android:width="@dimen/padding_2"
        android:color="@color/grey_darker" />

</shape>

И учитывая стиль также.

<style name="MyRadioButtonStyle" 
     parent="@android:style/Widget.CompoundButton.RadioButton">
            <item name="android:button">@drawable/radio_btn_selector</item>
        </style>

Что я делаю не так, пожалуйста, направьте меня.

1 Ответ

0 голосов
/ 06 марта 2019

Я думаю, вы пропустили установку свойства RadioButton android:background="@drawable/radio_btn_selector".

<RadioButton
            android:id="@+id/manual_rb"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="true"
            android:text="@string/manual"
            android:textColor="@color/textcolor"
            android:textSize="@dimen/fontsize_16"
            android:button="@android:color/transparent"
            android:background="@drawable/radio_btn_selector"
            />
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...