diff --git a/api/current.txt b/api/current.txt
index 6d2e9bad6..b808dba65 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -432,12 +432,14 @@ package android.support.design.widget {
method public boolean isCounterEnabled();
method public boolean isErrorEnabled();
method public boolean isHintAnimationEnabled();
+ method public boolean isHintEnabled();
method public void setCounterEnabled(boolean);
method public void setCounterMaxLength(int);
method public void setError(java.lang.CharSequence);
method public void setErrorEnabled(boolean);
method public void setHint(java.lang.CharSequence);
method public void setHintAnimationEnabled(boolean);
+ method public void setHintEnabled(boolean);
method public void setHintTextAppearance(int);
method public void setTypeface(android.graphics.Typeface);
}
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 0179ec7c8..3079180a8 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -162,6 +162,8 @@
If enabled, any non-empty hint in the child EditText will be moved into the floating + * hint, and its existing hint will be cleared. If disabled, then any non-empty floating hint + * in this layout will be moved into the EditText, and this layout's hint will be cleared.
+ * + * @see #setHint(CharSequence) + * @see #isHintEnabled() + * + * @attr ref android.support.design.R.styleable#TextInputLayout_hintEnabled + */ + public void setHintEnabled(boolean enabled) { + if (enabled != mHintEnabled) { + mHintEnabled = enabled; + + final CharSequence editTextHint = mEditText.getHint(); + if (!mHintEnabled) { + if (!TextUtils.isEmpty(mHint) && TextUtils.isEmpty(editTextHint)) { + // If the hint is disabled, but we have a hint set, and the EditText doesn't, + // pass it through... + mEditText.setHint(mHint); + } + // Now clear out any set hint + setHintInternal(null); + } else { + if (!TextUtils.isEmpty(editTextHint)) { + // If the hint is now enabled and the EditText has one set, we'll use it if + // we don't already have one, and clear the EditText's + if (TextUtils.isEmpty(mHint)) { + setHint(editTextHint); + } + mEditText.setHint(null); + } + } + + // Now update the EditText top margin + if (mEditText != null) { + final LayoutParams lp = updateEditTextMargin(mEditText.getLayoutParams()); + mEditText.setLayoutParams(lp); + } + } + } + + /** + * Returns whether the floating label functionality is enabled or not in this layout. + * + * @see #setHintEnabled(boolean) + * + * @attr ref android.support.design.R.styleable#TextInputLayout_hintEnabled + */ + public boolean isHintEnabled() { + return mHintEnabled; } /** @@ -318,7 +389,7 @@ public class TextInputLayout extends LinearLayout { mFocusedTextColor = ColorStateList.valueOf(mCollapsingTextHelper.getCollapsedTextColor()); if (mEditText != null) { - updateLabelVisibility(false); + updateLabelState(false); // Text size might have changed so update the top margin LayoutParams lp = updateEditTextMargin(mEditText.getLayoutParams()); @@ -442,7 +513,7 @@ public class TextInputLayout extends LinearLayout { // Set the EditText's background tint to the error color mErrorShown = true; updateEditTextBackground(); - updateLabelVisibility(true); + updateLabelState(true); } else { if (mErrorView.getVisibility() == VISIBLE) { ViewCompat.animate(mErrorView) @@ -454,7 +525,7 @@ public class TextInputLayout extends LinearLayout { public void onAnimationEnd(View view) { view.setVisibility(INVISIBLE); - updateLabelVisibility(true); + updateLabelState(true); } }).start(); @@ -547,7 +618,7 @@ public class TextInputLayout extends LinearLayout { length, mCounterMaxLength)); } if (mEditText != null && wasCounterOverflowed != mCounterOverflowed) { - updateLabelVisibility(false); + updateLabelState(false); updateEditTextBackground(); } } @@ -609,14 +680,17 @@ public class TextInputLayout extends LinearLayout { @Override public void draw(Canvas canvas) { super.draw(canvas); - mCollapsingTextHelper.draw(canvas); + + if (mHintEnabled) { + mCollapsingTextHelper.draw(canvas); + } } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); - if (mEditText != null) { + if (mHintEnabled && mEditText != null) { final int l = mEditText.getLeft() + mEditText.getCompoundPaddingLeft(); final int r = mEditText.getRight() - mEditText.getCompoundPaddingRight(); @@ -637,7 +711,7 @@ public class TextInputLayout extends LinearLayout { public void refreshDrawableState() { super.refreshDrawableState(); // Drawable state has changed so see if we need to update the label - updateLabelVisibility(ViewCompat.isLaidOut(this)); + updateLabelState(ViewCompat.isLaidOut(this)); } private void collapseHint(boolean animate) {