[英]Samsung Galaxy S7 Edge ignores datePickerMode
I am setting the datePickerMode
in my styles file to spinner
like this: 我将样式文件中的
datePickerMode
设置为spinner
如下所示:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:dialogTheme">@style/MyDialogTheme</item>
<item name="android:datePickerStyle">@style/MyDatePicker</item>
</style>
<style name="ItvDialogTheme" parent="android:Theme.Material.Light.Dialog">
<item name="android:datePickerStyle">@style/MyDatePicker</item>
</style>
<style name="MyDatePicker" parent="android:Widget.Material.Light.DatePicker">
<item name="android:datePickerMode">spinner</item>
</style>
and then create a DatePicker 然后创建一个DatePicker
DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(final DatePicker view, final int year, final int monthOfYear, final int dayOfMonth) {
//handle result
}
};
DatePickerDialog dialog = new DatePickerDialog(this, onDateSetListener, dob.getYear(), dob.getMonth() - 1,
dob.getDay());
dialog.show();
This worked fine across a lot of devices including the Samsung Galaxy S7 Edge on Android 6, but since updating the device to Android 7 it ignores the mode spinner
and shows the calendar. 这在许多设备(包括Android 6上的Samsung Galaxy S7 Edge)上都可以正常工作,但是由于将设备更新为Android 7,因此它会忽略模式
spinner
并显示日历。
The spinner works fine on an One Plus 3 on Android 7.1.1. 微调器可以在Android 7.1.1的One Plus 3上正常工作。
Any ideas? 有任何想法吗?
You may be running into this issue (#37120178) datepicker dialog can't switch to spinner on Android 7.0 device . 您可能会遇到此问题(#37120178)datepicker 对话框无法在Android 7.0设备上切换到Spinner 。 If so, there is a work-around documented on that page.
如果是这样,该页面上记录了解决方法。
I haven't tried the work-around, but it may be worth a shot. 我没有尝试解决方法,但是值得一试。 (See below for implementation of the work-around.) (有关变通办法的实施,请参见下文。)
By the way, I have a Samsung S7 (not an edge) running 7.0. 顺便说一句,我有运行7.0的三星S7(不是边缘)。 I can get a
DatePicker
spinner if I define it in XML, so another work-around would be to define the DatePicker
spinner in XML and use it in the dialog. 如果我以XML定义
DatePicker
微调器,则可以得到另一个解决方法,那就是以XML定义DatePicker
微调器并在对话框中使用它。
Here is a gist of this solution . 这是该解决方案的要点 。
Odd, but those fixes in the bug report seem to be for the time picker although the report is for the date picker. 奇怪,但是错误报告中的那些修复似乎是针对时间选择器的,尽管该报告是针对日期选择器的。 I dug around a bit and found Use DatePicker spinners in API 24 as a potential fix.
我仔细研究了一下,发现使用API 24中的DatePicker微调器可以解决问题。
Again, I have not tried this. 同样,我没有尝试过。
This reflection logic does appear to work. 这种反射逻辑确实起作用了。 It showed the spinner beside the calendar view for me.
它为我显示了微调器在日历视图旁边。 If you want just the spinner, you will need to add the following to your style:
如果只需要微调器,则需要在样式中添加以下内容:
<item name="android:calendarViewShown">false</item>
(Credit for this work-around goes to lognaturel and jeffdgr8 ). (此变通办法的信誉归于lognaturel和jeffdgr8 )。
Here is what my custom DatePickerDialog
looks like with the reflection logic: 这是我的自定义
DatePickerDialog
和反射逻辑的样子:
public class MyReflectionDatePickerDialog extends DatePickerDialog {
private DatePicker mDatePicker;
@RequiresApi(api = Build.VERSION_CODES.N)
public MyReflectionDatePickerDialog(@NonNull Context context, @Nullable OnDateSetListener listener,
int year, int month, int dayOfMonth) {
super(context, listener, year, month, dayOfMonth);
fixSpinner(context, year, month, dayOfMonth);
}
// include gist here from:
// https://gist.github.com/lognaturel/232395ee1079ff9e4b1b8e7096c3afaf
}
You would instantiate this custom view as shown below: 您将实例化此自定义视图,如下所示:
DatePickerDialog dialog;
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
dialog = new MyDatePickerDialog(this, onDateSetListener, dob.getYear(),
dob.getMonth() - 1, dob.getDay());
} else {
dialog = new DatePickerDialog(this, onDateSetListener, dob.getYear(),
dob.getMonth() - 1, dob.getDay());
}
You can try this. 你可以试试看
datePicker.setCalendarViewShown(false); datePicker.setCalendarViewShown(false);
由于Android 7.0,您应该尝试将targetSdkVersion提升至24
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.