Android 自定义微调器对话框:对话框的弹出背景设置

Android 自定义微调器对话框:对话框的弹出背景设置,android,android-spinner,Android,Android Spinner,我有一个旋转器,如下所示。虽然我可以设置行的样式(“raspberrypi-0”),但我无法更改对话框其余部分的任何内容 我想更改弹出窗口的背景色。如果可能,“为传感器选择设备”的颜色也应更改。下面是在线性布局中定义的微调器xml(未显示) 其中spinner\u下拉列表\u项只是一个文本视图 而且MaterialSpinner只是扩展了Spinner,所以大部分内容都应该适用。有关它的更多信息,请访问github 我通过破解MaterialSpinner的适配器代码解决了这个问题。在覆盖的ge

我有一个旋转器,如下所示。虽然我可以设置行的样式(“raspberrypi-0”),但我无法更改对话框其余部分的任何内容

我想更改弹出窗口的背景色。如果可能,“为传感器选择设备”的颜色也应更改。下面是在线性布局中定义的微调器xml(未显示)

其中
spinner\u下拉列表\u项
只是一个文本视图

而且MaterialSpinner只是扩展了Spinner,所以大部分内容都应该适用。有关它的更多信息,请访问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;
}
CustomArrayAdapter customArrayAdapter = new CustomArrayAdapter(parentActivity, R.layout.spinner_dropdown_item, devices);
customArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
registeredDevicesDropdown.setAdapter(customArrayAdapter);
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;
}