简体   繁体   English

Android RadioButton仅显示文本,而不显示设备模拟器中的实际按钮

[英]Android RadioButton shows only text, not the actual button in device emulator

I have a group of radio buttons displaying fine in my XML design window, but in the emulator (and on my actual device that I installed the app on) it only shows the button text and not the button. 我的XML设计窗口中有一组单选按钮,它们显示得很好,但是在仿真器(以及安装了该应用程序的实际设备上)中,它仅显示按钮文本,而不显示按钮。

截图

Here is the XML file for this activity: 这是此活动的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 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>

It looks fine in the preview but on my device and in the emulator is seems to exclude the radio buttons. 在预览中看起来不错,但在我的设备和仿真器上似乎排除了单选按钮。

You are using in a wrong way I guess use it as following: 您使用的方式有误,我猜是按以下方式使用:

First declare your custom styles in styles.xml file like this: 首先在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>

Once the style is done now all you need is to assign that particular style to your radio button or group like the following: 样式完成后,您只需要将特定样式分配给单选按钮或组,如下所示:

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

For more info take a look at the following links: 有关更多信息,请查看以下链接:

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

How to customize default theme of radio button in android? 如何在Android中自定义单选按钮的默认主题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MediaPlayer可在模拟器上运行,但不能在android中的实际设备上运行 - MediaPlayer working on emulator, but not on actual device in android Android - OpenGL - 仿真器与实际设备 - Android - OpenGL - Emulator vs Actual Device Android哈希代码不匹配:实际设备上出现onFacebookError,应用在模拟器上运行 - Android Hash code Mismatch : onFacebookError on actual device, app runs on emulator 后退按钮在模拟器上运行,但在Android设备中不运行 - back button is working on emulator but it is not working in device in android Android小部件仅在模拟器上有效,而不能在真实设备上有效 - Android widget works only on emulator not on real device Android单选按钮接受 - android radiobutton button accept 该图显示了在仿真器上但未在真实设备上显示 - Image shows on emulator but not on real device 按钮在模拟器上有效,但在设备上无效 - Button works on emulator but not on device 自定义SimpleAdapter仅显示示例文本Android - Custom SimpleAdapter only shows Sample Text Android Firebase Auth 给出 ViewPostIme 指针 1 在物理设备上运行但在 Android 模拟器上工作(Firebase 仅在模拟器上工作) - Firebase Auth gives ViewPostIme pointer 1 While running on a physical device but work on Android Emulator ( Firebase works only on emulator )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM