<android.support.design.widget.TextInputLayout
android:id="@+id/productLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<EditText
android:id="@+id/product"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_padding_width_height_6"
android:cursorVisible="false"
android:drawableRight="@drawable/ic_arrow_down"
android:focusableInTouchMode="false"
android:hint="@string/product"
android:inputType="none"
android:paddingEnd="@dimen/margin_padding_width_height_2"
android:paddingRight="@dimen/margin_padding_width_height_2"
android:singleLine="true"
android:textSize="@dimen/text_size_m" />
private boolean validateFields() {
if (mCategory.getText().toString().isEmpty())
mCategoryLayout.setError("Please select a category");
else if (mProducts.getText().toString().isEmpty())
mProductsLayout.setError("Please select a product");
else if (mSerialNumber.getText().toString().isEmpty())
mSerialNumberLayout.setError("Please enter the serial number");
else
return true;
return false;
}
I have implemented click listener for the EditText
,So I don't want float the EditText
label to top while setting error on TextInputLayout
. How do I disable that ?
Enabling/Disabling Floating Hints Floating Hints are enabled by default in a TextInputLayout. To disable it we need to add the following attribute inside the tag : app:hintEnabled="false" . The below xml code is from the activity_main. xml layout and has three EditText fields.
You should be able to call TextInputLayout. setErrorEnabled(false) to hide the error TextView and calling TextInputLayout. setError(error) now internally calls TextInputLayout. setErrorEnabled(true) if the error isn't null or empty.
You can remove extra space above AppCompatEditText by setting app:hintEnabled="false" to TextInputLayout but it won't display hint until you re-enable that. Save this answer. Show activity on this post. Save this answer.
Starting version 23.2.0 of the Support Library you can call
setHintEnabled(false)
or putting it in your TextInputLayout xml as such :
app:hintEnabled="false"
Though the name might makes you think it removes all hints, it just remove the floating one.
Related docs and issue: http://developer.android.com/reference/android/support/design/widget/TextInputLayout.html#setHintEnabled(boolean)
https://code.google.com/p/android/issues/detail?id=181590
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With