Timepicker对话框周围的空白空白

时间:2016-01-16 22:00:09

标签: android android-layout android-alertdialog android-theme

我正在尝试为我的应用程序创建时间选择器.. 将主题设置为Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth

我收到了这个输出

WEEKOFYEAR()

我在对话框周围出现空白

当我将其设置为使用父活动的主题appcompat.noactionbar

时,不会发生这种情况
//not happening here
  return new TimePickerDialog(getActivity(),this, hour, minute,is24HourView );

这是我的时间码代码

    public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener{

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState){
        //Use the current time as the default values for the time picker
        final Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);

        boolean is24HourView=true;
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        String formattedTime = sdf.format(c.getTime());
        Log.d("time", formattedTime);
        //Create and return a new instance of TimePickerDialog
//        return new TimePickerDialog(getActivity(),this, hour, minute,is24HourView );
      return new TimePickerDialog(getActivity(), android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth,this, hour, minute,is24HourView );

    }

2 个答案:

答案 0 :(得分:1)

我知道这很老了,但这是一个解决方案。

您可以在styles.xml中创建一个自定义主题,并将所选主题作为父主题,并将其android:windowBackground属性设置为@android:color/transparent

<style name="TimePickerDialogStyle" parent="@android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar.MinWidth">
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

然后将您的自定义主题传递给TimePickerDialog构造函数:

new TimePickerDialog(getActivity(), R.style.TimePickerDialogStyle, this, hour, minute, is24HourView);

答案 1 :(得分:0)

变化:

 android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth

 AlertDialog.THEME_DEVICE_DEFAULT_LIGHT

 AlertDialog.THEME_HOLO_LIGHT

应该有效