10

我知道這聽起來很奇怪,所以這裏是圖片。單選按鈕只是部分檢查

enter image description here

它持有正確的值。正確的單選按鈕(部分)被選中。 OnCheckedChangeListener中的所有邏輯都正確執行。我完全驚呆了。爲什麼單選按鈕沒有完全檢查?

只有我能想到的事情是,我使用Rx2Firebase

periodRetriever = FirebaseHelper.getInstance(getContext()).getPeriod() 
     .defaultIfEmpty(0) 
     .distinctUntilChanged() 
     .subscribe(new Consumer<Integer>() { 
      @Override 
      public void accept(@NonNull Integer headerType) throws Exception { 
       getRadioViewChecked(headerType).setChecked(true); 
      } 
     }); 

EDIT1

馬科斯建議我看不到白色的刻度。不是這種情況。 enter image description here

EDIT2

佈局:

<RadioGroup 
    android:id="@+id/rgPeriod" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <android.support.v7.widget.AppCompatRadioButton 
     android:id="@+id/rbMonth" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:checked="false" 
     android:text="@string/month" /> 

    <android.support.v7.widget.AppCompatRadioButton 
     android:id="@+id/rbWeek" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:checked="false" 
     android:text="@string/week" /> 

    <android.support.v7.widget.AppCompatRadioButton 
     android:id="@+id/rb4Weeks" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:checked="false" 
     android:text="@string/four_weeks" /> 


</RadioGroup> 
+0

你指的是一個事實,即圓不具有後點在中心?如果是這樣,你的主題是什麼,你做了什麼來定製'RadioButton'的外觀? – CommonsWare

+0

@CommonsWare是的,這就是我指的!除了設置'colorPrimary'和'colorAccent'之外,我沒有做過任何樣式的設計。當它全部同步時,我沒有這個問題。 –

+0

也許你延伸的主題使用白色選擇點 如果你使用黑色主題切換到光照或否則 –

回答

2

你的主題是黑暗的,你不能看到白色的刻度,則需要將其更改爲另一種顏色。

+1

Obs:我在8月28日評論過這個 –

+0

如果那是真的,改變我活動的背景顏色會揭示這個權利?但是,我的腦海裏又出現了一個新的問題,爲什麼它有時是白色的,有時不是? –

+0

它取決於您正在測試的設備,是的,chaning背景會使其顯示 –

0

試着改變你的主題或您的單選按鈕的顏色屬性

0

我不能看到Rx2Firebase

所以你可以嘗試使用自定義主題爲你的單選按鈕的任何問題?從白色到另一種顏色

<style name="MyRadioButton" parent="Theme.AppCompat.Light"> 
    <item name="colorControlNormal">@color/indigo</item> 
    <item name="colorControlActivated">@color/pink</item> 
</style> 

<RadioButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:checked="true" 
    android:text="4 weeks" 
    android:theme="@style/MyRadioButton"/> 

https://materialdoc.com/components/selection-controls/

1

更改背景顏色就會出現

+1

您是如何錯過該紅色圖片的? –

+0

對不起羅賓迪克霍夫先生 –

+0

我認爲他正在應用一些主題 –

0

您是否嘗試過使用RadioButton代替android.support.v7.widget.AppCompatRadioButton我認爲這可能會解決這個問題

在另一方面,在這裏你可以找到一個如何樣式RadioButtons文檔

http://www.materialdoc.com/radio-button/

  1. 在styles.xml文件中聲明自定義樣式。

<style name="MyRadioButton" parent="Theme.AppCompat.Light"> <item name="colorControlNormal">@color/indigo</item> <item name="colorControlActivated">@color/pink</item> </style>

  • 通過安卓應用這種風格到您的單選按鈕:主題屬性。
  • `

    <RadioButton 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:checked="true" 
         android:text="Radio Button" 
         android:theme="@style/MyRadioButton"/> 
    

    源:https://stackoverflow.com/a/35044856/4492504

    3

    看起來像一個動畫錯誤。在ViewPager中的Fragment上使用CompoundButton時,drawable狀態設置不正確。

    這種情況也適用於複選框,如下所示:Android Nougat: Why do checkboxes on Fragment have incomplete state when selected programmatically (but look fine on Lollipop)

    調用jumpDrawablesToCurrentState()只調用RadioGroup.check(ID)或Checkbox.setChecked(真)似乎解決這個問題(感謝@Dalmas)

    +0

    畢竟這些答案終於有意義的東西。 –

    +0

    這發生在Nexus 5x API 27上。該片段位於具有片段適配器的活動中。 #jumpDrawablesToCurrentState修復了它 – Reinherd