当放入Listview时,RadioButton的风格会神奇地改变?

时间:2015-05-21 12:29:41

标签: android android-layout android-listview android-radiobutton

我制作了DialogFragment RadioButton ontop和ListView,其中包含更多RadioButton s。现在我只想知道ListView使用的样式RadioButton与“独立”样式不同。

以下是我的dialog.xml的片段

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/buttonGroup"
        android:layout_alignParentTop="true"
        android:orientation="vertical">

        <RadioButton
            android:id="@+id/none"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/none" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/white" />

        <ListView
            android:id="@+id/conferences"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
</LinearLayout>

我的list_item.xml,我作为getView的{​​{1}}中的行充气:

ArrayAdapter

我的<?xml version="1.0" encoding="utf-8"?> <RadioButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/conference" android:layout_width="match_parent" android:layout_height="wrap_content" /> 基于AppTheme。我没有在视图中更改任何特定项目的样式。

“独立”"Theme.AppCompat"有一个白色圆圈,选中时带有蓝点,当你按下它时甚至会有不同的风格。 RadioButton中的RadioButton都是黑色的,带有黑点,并且没有“按下”样式。如果我不需要以编程方式设置未检查/“按下”/选中的样式,那将会很酷。我已经尝试设置2个基本的Android主题,在ListView的名称中有“RadioButton”,但没有任何改变。也许有办法获得“独立”ListView的风格并将其设置在其他RadioButton的xml文件中?

我会张贴一张图片,但我是新来的,所以不允许这样做。

更新

我将AppTheme改为:

RadioButton

<style name="AppTheme" parent="Theme.AppCompat"> <item name="android:textViewStyle">@style/TextAppearance.AppCompat.Large</item> <item name="android:radioButtonStyle">@style/RadioButtonStyle</item> </style> <style name="RadioButtonStyle"> <item name="android:textAppearance">@style/TextAppearance.AppCompat.Large</item> </style> 中的RadioButton已更改,但未更改为“{1}}”。当我将样式添加到ListView

RadioButton

文字发生了变化,但RadioButton圈仍然存在。对于<RadioButton android:id="@+id/none" style="@style/RadioButtonStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/none" /> 中的RadioButton,圈子已经消失......

1 个答案:

答案 0 :(得分:3)

确保LayoutInflater中的Adapter使用Activity上下文,而不是应用程序上下文。

<强>更新

请从您的样式中删除android前缀:

  <item name="radioButtonStyle">@style/RadioButtonStyle</item>

并按如下方式更新RadioButtonStyle

<style name="RadioButtonStyle" parent="@style/Widget.AppCompat.CompoundButton.RadioButton" />
相关问题