From 2036ae8c98bbe0ee595f70c7871d3f820646119f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Rodr=C3=ADguez?= Date: Wed, 17 Feb 2016 00:13:53 -0600 Subject: [PATCH] Set title after onCreateView Set title was only taking effect with the next onCreateView --- .../time/TimePickerDialog.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java b/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java index 7e7b214c..8eae5fee 100644 --- a/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java +++ b/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java @@ -104,6 +104,7 @@ public class TimePickerDialog extends DialogFragment implements private TextView mSecondView; private TextView mSecondSpaceView; private TextView mAmPmTextView; + private TextView mTimePickerHeader; private View mAmPmHitspace; private RadialPickerLayout mTimePicker; @@ -198,10 +199,18 @@ public void initialize(OnTimeSetListener callback, } /** - * Set a title. NOTE: this will only take effect with the next onCreateView + * Set a title. */ public void setTitle(String title) { - mTitle = title; + mTitle = title == null ? "" : title; + if (mTimePickerHeader != null) { + if (!mTitle.isEmpty()) { + mTimePickerHeader.setVisibility(TextView.VISIBLE); + mTimePickerHeader.setText(mTitle.toUpperCase(Locale.getDefault())); + } else { + mTimePickerHeader.setText(mTitle); + } + } } public String getTitle() { @@ -621,16 +630,13 @@ public void onClick(View v) { } // Set the title (if any) - TextView timePickerHeader = (TextView) view.findViewById(R.id.time_picker_header); - if (!mTitle.isEmpty()) { - timePickerHeader.setVisibility(TextView.VISIBLE); - timePickerHeader.setText(mTitle.toUpperCase(Locale.getDefault())); - } + mTimePickerHeader = (TextView) view.findViewById(R.id.time_picker_header); + setTitle(mTitle); // Set the theme at the end so that the initialize()s above don't counteract the theme. mOkButton.setTextColor(mAccentColor); mCancelButton.setTextColor(mAccentColor); - timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor)); + mTimePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor)); view.findViewById(R.id.time_display_background).setBackgroundColor(mAccentColor); view.findViewById(R.id.time_display).setBackgroundColor(mAccentColor);