Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行Android 7.x的三星galaxy S7上的DatePickerDialog显示错误_Android - Fatal编程技术网

运行Android 7.x的三星galaxy S7上的DatePickerDialog显示错误

运行Android 7.x的三星galaxy S7上的DatePickerDialog显示错误,android,Android,只有三星s7运行安卓7.x 这是我的密码 DatePickerDialog datePickerDialog = new DatePickerDialog(activity ,new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year

只有三星s7运行安卓7.x

这是我的密码

 DatePickerDialog datePickerDialog = new DatePickerDialog(activity
                ,new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year
                                          , int monthOfYear
                                          , int dayOfMonth) {
                        listener.onDateSet(year, monthOfYear, dayOfMonth);
                    }
                }
                ,c.get(Calendar.YEAR)
                , c.get(Calendar.MONTH)
                , c.get(Calendar.DAY_OF_MONTH));

        int firstDayOfWeek = TimeUtils.getFirstDayOfWeek(activity);
        datePickerDialog.getDatePicker().setFirstDayOfWeek(firstDayOfWeek);
        datePickerDialog.show();
有人建议我如何解决这个问题吗


谢谢

您没有为对话框设置自定义样式,因此此对话框为正常(默认样式)。如果要“修复”此“错误”,必须创建自定义样式对话框。

您没有为对话框设置自定义样式,因此此对话框为正常(默认样式)。如果你想“修复”这个“bug”,你必须创建自定义样式的对话框。

对于我来说,在同一台设备上工作正常,我在我的应用程序中扩展DialogFrament,并使用如下代码:

public static class DatePickerFragment extends DialogFragment
                            implements DatePickerDialog.OnDateSetListener {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current date as the default date in the picker
        final Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);

        // Create a new instance of DatePickerDialog and return it
        return new DatePickerDialog(getActivity(), this, year, month, day);
    }

    public void onDateSet(DatePicker view, int year, int month, int day) {
        // Do something with the date chosen by the user
    }
}
然后在需要打开对话框的视图上使用此方法:

public void showDatePickerDialog(View v) {
    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(getSupportFragmentManager(), "datePicker");
}
请尝试实现此功能,或按照开发人员网站上的指南进行操作:
对于我来说,在同一台设备上工作正常,我在我的应用程序中扩展了DialogFrament,并使用如下代码:

public static class DatePickerFragment extends DialogFragment
                            implements DatePickerDialog.OnDateSetListener {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current date as the default date in the picker
        final Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);

        // Create a new instance of DatePickerDialog and return it
        return new DatePickerDialog(getActivity(), this, year, month, day);
    }

    public void onDateSet(DatePicker view, int year, int month, int day) {
        // Do something with the date chosen by the user
    }
}
然后在需要打开对话框的视图上使用此方法:

public void showDatePickerDialog(View v) {
    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(getSupportFragmentManager(), "datePicker");
}
请尝试实现此功能,或按照开发人员网站上的指南进行操作:
问题在于
DatePickerDialog
的用户界面的实际实现是特定于设备的,可能存在一些问题

我在屏幕宽度小于360dp的设备上也遇到类似问题。使用
THEME\u HOLO\u LIGHT
THEME修复了此问题

DatePickerDialog
有一个接受主题的构造函数:

DatePickerDialog(Context context, int theme, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth)
您可以使用以下选项之一:

  • AlertDialog.THEME\u设备\u默认\u暗
  • AlertDialog.THEME\u设备\u默认\u灯
  • AlertDialog.THEME\u HOLO\u黑暗
  • AlertDialog.THEME_全息灯
  • AlertDialog.THEME_传统

问题在于,
日期选择器对话框
的UI的实际实现是特定于设备的,可能会有一些问题

我在屏幕宽度小于360dp的设备上也遇到类似问题。使用
THEME\u HOLO\u LIGHT
THEME修复了此问题

DatePickerDialog
有一个接受主题的构造函数:

DatePickerDialog(Context context, int theme, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth)
您可以使用以下选项之一:

  • AlertDialog.THEME\u设备\u默认\u暗
  • AlertDialog.THEME\u设备\u默认\u灯
  • AlertDialog.THEME\u HOLO\u黑暗
  • AlertDialog.THEME_全息灯
  • AlertDialog.THEME_传统

是的。我已经为它设定了主题。但不是工作。您有自定义样式。这里我的代码
@color/primary
您不明白,您必须以自定义样式编辑边距和填充,而不仅仅是更改颜色:染料。但价值有多大?因为我设置的边距和填充是0dp,所以它不起作用。可能你必须从根目录(android:Widget.DatePicker)开始,编辑许多内容,然后向上或创建自己的日历布局,并替换默认数据采集器的默认布局。如果我使用25.1.0或更新版本,我认为谷歌支持v7的问题。是的。我已经为它设定了主题。但不是工作。您有自定义样式。这里我的代码
@color/primary
您不明白,您必须以自定义样式编辑边距和填充,而不仅仅是更改颜色:染料。但价值有多大?因为我设置的边距和填充是0dp,所以它不起作用。可能你必须从根目录(android:Widget.DatePicker)开始,编辑许多内容,然后向上或创建自己的日历布局,并替换dataPicker的默认布局。如果我使用25.1.0或更新版本,我认为谷歌支持v7的问题。