2016-03-03 151 views
1

我有一個微調器,如下所示。雖然我可以設置該行的樣式(「raspberrypi-0」),但我無法爲該對話框的其餘部分更改任何內容。自定義微調器對話框:對話框的popupbackground設置

我想改變彈出的背景顏色。如果可能的話,「選擇傳感器的設備」的顏色也應該改變。下面是我在線性佈局內定義的微調器的xml(未顯示)。

<fr.ganfra.materialspinner.MaterialSpinner 
    android:id="@+id/attached_device_value_dropdown" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:spinnerMode="dialog" 
    app:ms_alignLabels="false" 
    app:ms_arrowSize="@dimen/spinner_arrow_size" 
    app:ms_hint="@string/attached_device_select" 
    app:ms_enableErrorLabel="true" 
    app:ms_multiline="true" 
    app:ms_floatingLabelColor="@color/black" 
    app:ms_hintColor="@color/light_grey" 
    app:ms_baseColor="@color/black" 
    app:ms_highlightColor="@color/black" 
    app:ms_arrowColor="@color/black"/> 

類似的設置:popupBackground存在當一個設定微調模式到「下拉菜單」。我正在尋找類似的東西,但爲了對話。

在Java中,這是我怎麼設置我的微調:

CustomArrayAdapter customArrayAdapter = new CustomArrayAdapter(parentActivity, R.layout.spinner_dropdown_item, devices); 
customArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
registeredDevicesDropdown.setAdapter(customArrayAdapter); 

其中spinner_dropdown_item只是一個文本視圖。

另外MaterialSpinner只是擴展了Spinner,所以大部分的東西都應該適用。 Here是關於它在github上的更多信息。

enter image description here

回答

1

我通過黑客的MaterialSpinner適配器代碼解決它。在您重寫的getCustomView函數中,設置背景和文本的顏色。

public View getCustomView(int position, View convertView, ViewGroup parent, boolean isDropDownView) { 
    //TODO: use convert view. 
    LayoutInflater inflater = (LayoutInflater) getActivity() 
     .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    final int resid = isDropDownView ? android.R.layout.simple_spinner_dropdown_item : android.R.layout.simple_spinner_item; 
    TextView row = (TextView) inflater.inflate(resid, parent, false); 
    row.setText(devices.get(position).getDeviceLabel()); 

    //Hack: Cannot set the dialogs color from XML and text color from XML               
    row.setTextColor(ContextCompat.getColor(parentActivity, R.color.black));  //set Text Color for the row content 
    parent.setBackgroundColor(ContextCompat.getColor(parentActivity, R.color.colorSecondary));  //set backgraound color ofr skeleton. 
    return row; 
}