我使用datePicker输入日期。
<style name="DatePickerTheme" parent="@android:style/Theme.Holo.Light.Dialog.MinWidth">
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>
并在Activity.java中
public void showDatePickerDialog(View v) {
DialogFragment newFragment = new Login.DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");
}
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new DatePickerDialog(getActivity(), R.style.DatePickerTheme, this, 1995, 0, 1);
}
public void onDateSet(DatePicker view, int year, int month, int day){
dateSelected = year+"-"+month+"-"+day;
}
}
问题是我得到了一个我不想要的背景图块。
但我想要
答案 0 :(得分:1)
我刚用 kotlin 解决了上面的问题。对于样式 AlertDialog.THEME_HOLO_DARK ,已弃用,而不是代码。
val c = Calendar.getInstance()
val year = c.get(Calendar.YEAR)
val month = c.get(Calendar.MONTH)
val day = c.get(Calendar.DAY_OF_MONTH)
val dpd = DatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth,
DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
var calendar = GregorianCalendar(year,monthOfYear,dayOfMonth)
setDate(calendar)
}, year, month, day)
dpd.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dpd.show()
答案 1 :(得分:1)
此行可以帮助您:
datePickerDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);