TextInputLayout & TextInputEditText hint - android

This is my xml code to make a input text for user phone number
but when it unfocused the hint label showed with larger text size
my question is how to make the hint label activated like password even when there is no text in the field.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/colorText">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/phone_number"
android:inputType="number"
android:maxLines="1"
android:textColorHint="#color/colorText" />
</android.support.design.widget.TextInputLayout>

Your hint is in the wrong place
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/phone_number"
android:textColorHint="#color/colorText">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLines="1"
android:textColorHint="#color/colorText" />
</android.support.design.widget.TextInputLayout>

Related

Removing space between design widgets

I am currently learning some design on XML. I have a scroll view and I have Several widgets. However, I want to remove space between my Log In and my password, how can I combine them together yet be able to input email and password?
What I want :
enter image description here
what I currently have
enter image description here
Thanks for the help.
So below is my simple code. How can I remove space and have them come together?
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="0dp">
<EditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/white"
android:hint="Email"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginBottom="8dp">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="38dp"
android:background="#color/white"
android:hint="Password"
android:inputType="textPassword"
android:textColorHint="#color/black" />
</android.support.design.widget.TextInputLayout>
You can remove extra top spacing by setting app:hintEnabled="false" to TextInputLayout:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:hintEnabled="false"
android:layout_marginBottom="0dp">
.....
It is space left for hint
Try changing the top/bottom margins of the EditText widgets. Like so:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="0dp">
<EditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/white"
android:hint="Email"
android:inputType="textEmailAddress"
android:layout_marginBottom="0dp"
/>
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginBottom="8dp">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="38dp"
android:background="#color/white"
android:hint="Password"
android:inputType="textPassword"
android:textColorHint="#color/black"
android:layout_marginTop="0dp"
/>
</android.support.design.widget.TextInputLayout>
I would also experiment with the android:padding attribute.
More info: Difference between a View's Padding and Margin
You can put login view and password view into linear layout, and margin_top and margin_bottom = 0
It's not about space between views, it's about view style. So search for style you need your EditText appears
Something like this tutorial

How to display Superscripted hint in TextInputLayout in Android? I can't seem to figure it out.Here's my code

Here's my Activity.xml file. I put the AppCompatEditText inside TextInputLayout. I want the hint to be shown in the html form with superscript text but it just won't happen. All the text is shown as just normal text. Is there a way around?
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/acceleration_unit_ms2"
android:inputType="numberDecimal"
android:id="#+id/acceleration_unit_ms2"/>
</android.support.design.widget.TextInputLayout>
Strings.xml
<string name="acceleration_unit_ms2">Meter/Second Square (m/s<sup><small>2</small></sup>)</string>
According to efficient performance use TextInputEditText inside TextInputLayout.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/input_layout_email"
android:layout_marginTop="#dimen/dp_10"
app:hintEnabled="true"
app:hintAnimationEnabled="false">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edit_email"
android:inputType="textEmailAddress"
android:hint="#string/email"
android:textSize="16sp"/>
</android.support.design.widget.TextInputLayout>

How to make edit text error position in android?

I have an app in which I have edit text fields in which I have to enter a mobile number and password. The problem is that the EditText error indicator covers the mobile number and password filed, and the user will not be able to enter mobile number. How do I solve this?
Use this android.support.design.widget.TextInputLayout.
which can show the error below to the Edittext.so You can easily write next thing like your number and password in the new Edittext.
Here is xml code :
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="60dp">
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="#string/hint_name" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_email"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="#string/hint_email" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="#string/hint_password" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
Let's see the ScreenShot for understand.
Empty Edittext.
Error message Edittext.
#Nitin: Actually Edittext behaviour wants you to focus in the edittext to discard the seterror message to rectify the erroneous data and go to other fields.

Android Material EditText

I'm using Support Design Library. I created EditText but when I'm writting something there is some blue underline of edit text like in the picture below
Here is my code:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Test"
android:inputType="none"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
How to fix that?
It seems autocomplete/suggestions are open. Try this:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Test"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>

There is any possibility to approach label with EditText in TextInputLayout?

when i put 2 or 3 TextInputLayout, label seams link graphically to previous editText instead of next. i need to put much marginTop to TextInputLayout. there is any possibility to approach label with EditText?
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name"
android:inputType="textCapWords" />
</android.support.design.widget.TextInputLayout>
in this example we can see margin from hint and edittext
Changing the paddingTop of the EditText should fix it, for example:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="0dp"
android:hint="#string/name"
android:inputType="textCapWords" />
</android.support.design.widget.TextInputLayout>
You can definitely add properties to TextInputLayout however you want it to be. Following will help you to add marginTop from exactly above Viewof TextInputLayout
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name"
android:inputType="textCapWords" />
</android.support.design.widget.TextInputLayout>

Categories

Resources