我有一个微调器,如下所示。虽然我可以为该行设置样式(“raspberrypi-0”),但我无法为对话框的其余部分更改任何内容。
我想更改弹出窗口的背景颜色。如果可能,还应更改“为传感器选择设备”的颜色。下面是我在线性布局(未显示)中定义的微调器的 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
只是一个 TextView 。
此外,MaterialSpinner 只是扩展了 Spinner,因此大部分内容都适用。 Here在 github 上有更多关于它的信息。
最佳答案
我通过破解 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;
}
关于android - 自定义微调器对话框 : popupbackground setting for dialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35775964/