如何在DatePickerDialog中删除多余的空间(在Android M&N上看到)?
作者:互联网
我在DatePickerDialog的右侧看到了一个额外的空间,仅在Android M& N版.在基于L的构建中没有观察到它.这是截图:
有人遇到过这个问题吗?
这是DatePickerFragment的实现:
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
public static DatePickerFragment newInstance(int day, int month, int year)
{
DatePickerFragment frag = new DatePickerFragment();
Bundle args = new Bundle();
args.putInt("day", day);
args.putInt("month", month);
args.putInt("year", year);
frag.setArguments(args);
return frag;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
int year = getArguments().getInt("year");
int month = getArguments().getInt("month");
int day = getArguments().getInt("day");
DatePickerDialog datePickerDialog =new DatePickerDialog(getActivity(), this, year, month, day);
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
return datePickerDialog;
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
try
{
DatePickerDialogListener listener = (DatePickerDialogListener)getActivity();
listener.onFinishDatePickDialog(year, monthOfYear + 1, dayOfMonth);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
// 1. Defines the listener interface with a method passing back data result.
public interface DatePickerDialogListener {
void onFinishDatePickDialog(int year, int monthOfYear, int dayOfMonth);
}
}
这里是样式表,它有一个android的组件:datePickerDialogTheme
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowContentTransitions">true</item>
<item name="colorControlNormal">@color/colorAccent</item>
<item name="colorControlActivated">@color/colorAccent</item>
<item name="colorControlHighlight">@color/colorAccent</item>
<item name="textColorError">@android:color/holo_red_dark</item>
<item name="android:timePickerDialogTheme">@style/AlertDialogCustom</item>
<item name="android:datePickerDialogTheme">@style/AlertDialogCustom</item>
<item name="android:alertDialogTheme">@style/AlertDialogCustom</item>
</style>
<style name="AlertDialogCustom" parent="android:Theme.Material.Light.Dialog.Alert">
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorAccent">@color/colorAccent</item>
</style>
注意:如果我不使用样式来修改颜色,则不会出现此问题.
解决方法:
不要使用Theme.AppCompat.Light.Dialog.Alert,只需使用Theme.AppCompat.Light.Dialog即可.当你看里面时,
< style name =“Base.ThemeOverlay.AppCompat.Dialog.Alert”>
< item name =“android:windowMinWidthMajor”> @ diem / abc_dialog_min_width_major< / item>
< item name =“andorid:windowMinWidthMinor”> @ dimen / abc_dialog_min_width_minor< / item>
< /风格>
风格有额外的尺寸修改,结果是不受欢迎的.
标签:android,android-styles,android-datepicker 来源: https://codeday.me/bug/20190627/1310000.html