0

I made a DialogFragment with a RadioButton ontop and a ListView below containing more RadioButtons. And now I'm just wondering what style the ListView uses that the RadioButtons don't look the same as the "stand-alone" one.

Here is a snippet of my 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>

And my list_item.xml that I inflate as the rows in getView of my 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" />

My AppTheme is based on "Theme.AppCompat". I didn't change any style of a specific item in my View.

The "stand-alone" RadioButton has a white circle with a blue dot when selected and even has a different style while you press it down. The RadioButtons in the ListView are all black with a black dot and don't have a "press-down" style. It would be cool if I wouldn't need to programatically set styles for not checked/"press-down"/checked. I already tried to set 2 base Android themes that had "RadioButton" in their names on the ListView but nothing changed. Maybe there is a way to get the style of the "stand-alone" RadioButton and set it in the xml files for the other RadioButtons?

I would post an image but I'm new here so not already allowed to do this.

Update

I changed my AppTheme to this:

<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>

And the RadioButtons in the ListView changed but not the "stand-alone" one. When I add the style to the RadioButton:

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

the text changes but the RadioButton-circle is still there. For the RadioButtons in the ListView the circles are gone...

cherry-wave
  • 731
  • 2
  • 6
  • 21
  • "I would post an image but I'm new here so not already allowed to do this" -- you are welcome to upload an image elsewhere and link to it from your question. Beyond that, please post the code for your `ListAdapter` where you are using this layout. – CommonsWare May 21 '15 at 12:30
  • Thanks, didn't thought about adding a link ;D – cherry-wave May 21 '15 at 13:42

1 Answers1

3

Make sure that LayoutInflater in your Adapter uses Activity context and not the application context.

Update:

Please remove android prefix from your style:

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

And update RadioButtonStyle as follows:

<style name="RadioButtonStyle" parent="@style/Widget.AppCompat.CompoundButton.RadioButton" />
questioner
  • 2,283
  • 3
  • 26
  • 35
  • It does but I found something out... I've added an update to my post. – cherry-wave May 21 '15 at 13:35
  • I am sorry for my late response. I tried this but that didn't change anything... So I added the android prefix again and set parent to "@android:style/Widget.CompoundButton.RadioButton" but still no change. I added ?android:attr/textAppearanceLarge to my RadioButtonStyle and at least the text changes for ALL RadioButtons (although I still have to add the style manually to the single RadioButton). But the circle is still different between standalone and listview radiobuttons – cherry-wave May 26 '15 at 10:56