0
我有一個日期選擇器對話框。我只想顯示日和月。年份選取器對話框必須隱藏。我已經嘗試其他答案,如this。沒有任何作品適合我。它也應該支持Kitkat到牛軋糖設備。我的日期選擇器代碼如下。如何在Kotlin(Android)的日期選擇器對話框中僅顯示日期和月份?
fun setDatePickerDialog() {
mDobDialog = DatePickerDialog([email protected], R.style.VDDatePickerDialogTheme, DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
val newDate = Calendar.getInstance()
newDate.set(year, monthOfYear, dayOfMonth)
//dob_textview.setText("($dayOfMonth) ($monthOfYear) ($year)")
val dateFormat = SimpleDateFormat(VDAppConstants.DOB_DISPLAY_FORMAT)
dob_textview?.setText(dateFormat.format(newDate.time))
}, mNewCalendar.get(Calendar.YEAR), mNewCalendar.get(Calendar.MONTH), mNewCalendar.get(Calendar.DAY_OF_MONTH))
mNewCalendar.set(1978,
mNewCalendar.get(Calendar.MONTH),
mNewCalendar.get(Calendar.DAY_OF_MONTH))
mDobDialog?.datePicker?.maxDate = mNewCalendar.timeInMillis
}
以下代碼僅適用於Kitkat設備,但不適用於牛軋糖設備。
val mDobDialog = DatePickerDialog([email protected], android.R.style.Theme_Holo_Dialog, DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
// Display Selected date in textbox
//date.setText("" + dayOfMonth + " " + monthOfYear + ", " + year)
}, year, month, day)
mDobDialog.show()
// Hide Year Selector in Date Picker
mDobDialog.findViewById(Resources.getSystem().getIdentifier("year", "id", "android")).visibility = View.GONE
如何從日期選擇器獲得一年場?你能否請加一些代碼 –
@VinayakB我更新了答案看看。 –
我正在使用datepicker對話框 –