gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:25:58 25 4
gpt4 key购买 nike

我有一组单选按钮在我的 XML 设计窗口中显示良好,但在模拟器中(以及在我安装应用程序的实际设备上),它只显示按钮文本,而不显示按钮。

screenshot

以下是此 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>

样式.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>

它在预览中看起来不错,但在我的设备和模拟器中似乎排除了单选按钮。

最佳答案

您使用的方式是错误的,我猜使用方式如下:

首先在 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

How to customize default theme of radio button in android?

关于java - Android RadioButton 仅显示文本,而不显示设备模拟器中的实际按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53954646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com