0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Androidで、タイトル付きの日付選択スピナーを作成する

Posted at

意外に記事がなかったのでメモ

以下のようにダイアログをカスタムし、


package com.example.buttonsandbox;

import android.app.DatePickerDialog;
import android.content.Context;
import android.widget.DatePicker;

class MyDatePickerDialog extends DatePickerDialog {
    public CharSequence title;

    public MyDatePickerDialog(Context context, int style, String title, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) {
        super(context, style, callBack, year, monthOfYear, dayOfMonth);
        this.title = title;
        setTitle(title);
    }

    @Override
    public void onDateChanged(DatePicker view, int year, int month, int day) {
        super.onDateChanged(view, year, month, day);
        setTitle(title);
    }
}

スピナーのスタイルを与える。


// styles.xml
// SpinnerDatePickerStyle
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="SpinnerDatePickerStyle" parent="android:Theme.Material.Dialog">
        <item name="android:datePickerStyle">@style/SpinnerDatePicker</item>
    </style>

    <style name="SpinnerDatePicker" parent="android:Widget.Material.DatePicker">
        <item name="android:datePickerMode">spinner</item>
    </style>
</resources>

そして呼び出す。

new MyDatePickerDialog(this, R.style.SpinnerDatePickerStyle, "Set birthday", dateSelectedListener, 1990, 0, 1).show();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?