Aman Verma
Aman Verma

Reputation: 3325

How to set the DatePickerDialog title?

I implemented a DatePickerDialog and I wanted to set a title which shows the reason to show this dialog like "Select Date of Birth" or so.

Downloaded from Google. The DatePickerDialog image.

I want to set the Title of this DatePickerDialog. I tried using the below code :

DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), this, year, month, day);
            Calendar calender = Calendar.getInstance();
            calender.set(2006, 11, 31);//Year,Mounth -1,Day
            datePickerDialog.getDatePicker().setMaxDate(calender.getTimeInMillis());
            datePickerDialog.setTitle("skmaskdaskldm");
            return datePickerDialog;

But it is not visible. is there any other way? I have tried using the Customtitle using below code:

TextView tv = new TextView(getActivity());

            // Create a TextView programmatically
            ViewGroup.LayoutParams lp = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, // Width of TextView
                    ViewGroup.LayoutParams.WRAP_CONTENT); // Height of TextView
            tv.setLayoutParams(lp);
            tv.setPadding(10, 10, 10, 10);
            tv.setGravity(Gravity.CENTER);
            tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP,20);
            tv.setText("This is a custom title.");
            tv.setTextColor(Color.parseColor("#ff0000"));
            tv.setBackgroundColor(Color.parseColor("#FFD2DAA7"));
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), this, year, month, day);
            datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis());
            mCalendar.add(Calendar.DATE, 45);
            datePickerDialog.getDatePicker().setMaxDate(mCalendar.getTimeInMillis());
            datePickerDialog.setCustomTitle(tv);
            return datePickerDialog;

Still not working using this code.

Upvotes: 4

Views: 3949

Answers (1)

NevrGivApp
NevrGivApp

Reputation: 39

I solved by using .setMessage method instead of .setTitle. Of course, it's not the same but I didn't need a bold title for my window.

Upvotes: 2

Related Questions