这很奇怪,我在我的自定义对话框中有一个timePicker,问题是它在某些版本的android上看起来不错但在android 5.0.2中,它会得到这样的黑色背景颜色:
{{3}}
如您所见,时钟背景已更改,但我没有做任何更改。
final Dialog dialog = new Dialog(SabadKharid_s1.this, R.style.DialogStyler2);
dialog.setContentView(R.layout.dialogtime);
timePicker = (TimePicker) dialog.findViewById(R.id.timePicker);
timePicker.setIs24HourView(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog.show();
dialog.getWindow().setAttributes(lp);
这是我使用的风格:
<style name="DialogStyler2" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowNoTitle">true</item>
</style>
如何解决此问题?
答案 0 :(得分:0)
你在屏幕上弹出的内容......对话可能有默认主题。
尝试为弹出窗口使用自定义主题...它会更改背景颜色或设置弹出窗口的自定义视图,并将布局设置父背景设置为android:background="@andrid:color/transparent"
答案 1 :(得分:0)
我想不出您在对话框中使用时间选择器的原因,您可以直接使用Material Time Pickers。
您可以使用它来获得更简单的解决方案。 https://github.com/wdullaer/MaterialDateTimePicker
TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) {
//Do your thing
);
timePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
//do your thing for cancel event
}
});
timePickerDialog.setAccentColor(ContextCompat.getColor(mContext, R.color.colorPrimary));
timePickerDialog.show(getFragmentManager(), TAG);
答案 2 :(得分:0)
尝试使用TimePickerDialog
。
// Initialize time picker
Calendar c = Calendar.getInstance();
int curHour = c.get(Calendar.HOUR_OF_DAY);
int curMinute = c.get(Calendar.MINUTE);
boolean is24HourView = true;
// Construct time picker dialog
TimePickerDialog dialogTimePicker = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute)
{
// Do something
}
}, curHour, curMinute, is24HourView);
// Show time picker dialog
dialogTimePicker.setTitle("Time Picker");
dialogTimePicker.show();
希望这会有所帮助〜