我正在尝试为我的应用程序创建时间选择器..
将主题设置为Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth
我收到了这个输出
我在对话框周围出现空白
当我将其设置为使用父活动的主题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 );
}
答案 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
应该有效