Android RadioButton показывает только текст, а не фактическую кнопку в эмуляторе устройства - PullRequest
0 голосов
/ 28 декабря 2018

У меня есть группа переключателей, которые хорошо отображаются в моем окне XML-дизайна, но в эмуляторе (и на моем реальном устройстве, на котором я установил приложение) отображается только текст кнопки, а не кнопка.

screenshot

Вот XML-файл для этого действия:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Question1">

<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="25dp"
    android:layout_marginLeft="25dp"
    android:layout_marginEnd="25dp"
    android:layout_marginRight="25dp"
    android:orientation="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0">

    <TextView
        android:id="@+id/errorView"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:text="@string/error_msg"
        android:textColor="@android:color/holo_red_light"
        android:visibility="invisible" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:text="@string/my_gender_is"
        android:textSize="20sp"
        android:textStyle="bold" />

    <RadioGroup
        android:id="@+id/gender_group"
        android:layout_width="match_parent"
        android:layout_height="100dp">

        <RadioButton
            android:id="@+id/radio_male"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="@string/male"
            android:textColor="#636363"
            android:textSize="18sp" />

        <RadioButton
            android:id="@+id/radio_female"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/female"
            android:textColor="#636363"
            android:textSize="18sp" />

    </RadioGroup>

</LinearLayout>

<Button
    android:id="@+id/nextPage"
    android:layout_width="120dp"
    android:layout_height="50dp"
    android:layout_marginStart="15dp"
    android:layout_marginLeft="15dp"
    android:layout_marginBottom="15dp"
    android:layout_weight="1"
    android:background="@color/colorPrimary"
    android:fontFamily="@font/segoeuil"
    android:gravity="center"
    android:includeFontPadding="false"
    android:paddingTop="-9dp"
    android:paddingBottom="5dp"
    android:text="@string/next"
    android:textAlignment="gravity"
    android:textAllCaps="false"
    android:textSize="26sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>

Styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:colorBackground">@color/background</item>

    </style>

    <!-- No title bar theme -->
    <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:colorBackground">@color/background</item>
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textColorPrimaryInverse">@color/primary_text_material_dark</item>
    </style>

</resources>

В предварительном просмотре выглядит хорошо, но на моемУстройство и в эмуляторе, похоже, исключают радио кнопки.

1 Ответ

0 голосов
/ 28 декабря 2018

Вы используете неправильно, я думаю, используйте его следующим образом:

Сначала объявите ваши пользовательские стили в styles.xml файле, например:

    <style name="MyRaidoButton" parent="Widget.AppCompat.CompoundButton.RadioButton">
    <item name="colorAccent">#0091ea</item>
    <item name="android:textColorPrimaryDisableOnly">#f44336</item>
    <item name="android:textAppearance">@style/TextAppearance.AppCompat</item>
</style>

Как только стиль будет готовтеперь все, что вам нужно, это назначить этот конкретный стиль вашей радиокнопке или группе, как показано ниже:

<RadioButton
android:id="@+id/products"
. . .
android:theme="@style/MyRaidoButton"/>

Для получения дополнительной информации перейдите по следующим ссылкам:

http://www.zoftino.com/android-ui-control-radiobutton

Как настроить тему по умолчанию для радио кнопки в Android?

...