I would like for my app to be able to display different hints in the edittext at different times, so i have to set the hint pro-grammatically at each times as below.
editText.setHint("Hint 1");
But the problem is when i starts typing the hint starts disappearing.I want to show this hint every time.If i set the hint in xml it will not disappear while typing, but how to do this in my case.
Either you should consider to change to TextInputLayout(Strongly recommended this. Here is an example too.)
or
make relative layout with EditText for input and TextView for hint inside.Change the textview according to your needs.
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some text"
android:layout_alignParentLeft="true"
android:id="#+id/editText1"
android:layout_gravity="center"
/>
<TextView
android:id="#+id/text_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="yourHint"
android:textSize="14sp"
android:layout_marginRight="10dp"
android:textColor="#color/customColor"
/>
</RelativeLayout>
what you are expecting is not possible,since we have to how what user is writing on editext.
Now a days https://github.com/hardik-trivedi/FloatingLabel
this type of hints are more popular,you can try above link.
TextInputLayout give powerful material features to EditText. Main feature is floating hint. See doc here https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html
You can't display while typing text in edit text hint in android have default functionality
<android.support.design.widget.TextInputLayout
android:theme="#style/TextLabel"
android:id="#+id/input_layout_username"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/username_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:hint="Email Address"
android:inputType="textEmailAddress"
android:translationY="10dp"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/font_13"/>
</android.support.design.widget.TextInputLayout>
Here android provide default functionality while typing text in edit text the hint above edit text, You can also set Hint via programmatically
EditText. setHint ("Hint 1");
the best way to do this is to use TextInputLayout.
https://www.bignerdranch.com/blog/becoming-material-with-android-design-support-library/
<!--EMAIL-->
<android.support.design.widget.TextInputLayout
android:id="#+id/email_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel">
<EditText
android:id="#+id/etUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/login_screen_email_hint"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLines="1"
android:nextFocusDown="#+id/etPassword"
android:singleLine="true"
android:textColor="#android:color/white"
android:textColorHighlight="#android:color/white"
android:textColorHint="#android:color/white" />
</android.support.design.widget.TextInputLayout>
And dont forget adding this line to your gradle file
compile 'com.android.support:design:23.4.0'
Related
In my app, I have a TextInputLayout where the user enters its id, when the TextInputLayout does not have the focus looks like:
However, when the user touch the TextInputLayout (get the focus) the hint text looks like:
And I need hint text looks like as the follow image when the TextInputLayout have the focus:
Ignore the icon, its different but it does not matter in this moment, that I want to do is the hint text looks like the last image
Here is my code:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/ilUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:textColorHint="#color/et_login">
<EditText
android:id="#+id/etUser"
android:layout_width="match_parent"
android:layout_height="#dimen/et_login_height"
android:background="#drawable/edit_text_format"
android:drawableLeft="#drawable/user"
android:drawablePadding="10dp"
android:fontFamily="sans-serif"
android:hint="#string/user_id_text_hint"
android:inputType="number"
android:maxLength="12"
android:minLines="15"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textCursorDrawable="#drawable/cursor_drawable_app"
android:textSize="#dimen/h5"
android:theme="#style/EditTextTheme" />
</com.google.android.material.textfield.TextInputLayout>
you cant do this by default edit text you can use some library in your app to apply this ...
library is here :
implementation 'com.google.android.material:material:1.2.1'
and if you want to learn i recommend to see this tutorial :
https://www.youtube.com/watch?v=C_TEugAIMHA&t=616s
see this and you can get your answer...
When you use TextInputLayout is highly recommended to use TextInputEditText instead of EditText
Example:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/ilUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:textColorHint="#color/et_login">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etUser"
android:layout_width="match_parent"
android:layout_height="#dimen/et_login_height"
android:background="#drawable/edit_text_format"
android:drawableLeft="#drawable/user"
android:drawablePadding="10dp"
android:fontFamily="sans-serif"
android:hint="#string/user_id_text_hint"
android:inputType="number"
android:maxLength="12"
android:minLines="15"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textCursorDrawable="#drawable/cursor_drawable_app"
android:textSize="#dimen/h5"
android:theme="#style/EditTextTheme" />
</com.google.android.material.textfield.TextInputLayout>
That should solve it!
enter image description hereI am using 2 type edit text in my login page. In Arabic EditText gravity is END.But hint in EditText getting left align Why?. When i give inputType="textPassword" no issues. Issues in android:inputType="textEmailAddress"
EditText code given below
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/userName"
android:inputType="textEmailAddress"
android:gravity="end"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/password"
android:inputType="textPassword"
android:gravity="end" />
Try removing :
android:gravity="end"
In the first EditText. It should automatically make the text RTL if you already placed arabic values-ar in values folder.
Don't forget to add:
android:supportsRtl="true"
In AndroidManifest.xml also.
Update;
Didn’t get you at first but, add these:
android:layoutDirection="rtl"
android:textDirection="rtl"
This will make the layout & text direction rtl and should help for the purpose.
Try with this
<EditText
android:id="#+id/username"
style="#style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:hint="#string/username"
android:layoutDirection="locale"
android:padding="10dip"
android:textDirection="locale" />
<EditText
android:id="#+id/password"
style="#style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:hint="#string/password"
android:layoutDirection="locale"
android:padding="10dip"
android:textDirection="locale" />
Is there a way to create an input field that looks like the ones on this image - Icon on the left, input on the right - using only the default TextInputLayout?
I've tried several combinations, and the icon always stays inside the TextInputEditText. I've tried changing the TextInputLayout orientation to horizontal but it didn't work as well. Is there anyway of doing this without placing an ImageView and an EditText inside of another ViewGroup?
Below is the code I used to create an input field, but with the icon remains inside the TextInputEditText.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Test"
>
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="#drawable/ic_bank_card_back_grey_24dp"
android:drawablePadding="#dimen/default_padding"
/>
</android.support.design.widget.TextInputLayout>
Does this fit the bill ? :
<android.support.design.widget.TextInputLayout
android:id="#+id/TextInputLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<android.support.v7.widget.AppCompatEditText
android:id="#+id/EditText1"
android:hint="code"
android:text="0044"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="phone"
android:minWidth="350dp"
android:drawableLeft="#drawable/cross"
android:drawableStart="#drawable/cross"
android:textColor="#00ff00"
android:textColorHint="#ff0000"
android:textCursorDrawable="#null"
/>
</android.support.design.widget.TextInputLayout>
image from code:
In Below Mentioned Code i am not able to see the hint text in nexus phone, in other phone it is working fine, and looks according to code.
<android.support.design.widget.TextInputLayout
android:id="#+id/til"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="#style/TextAppearence.App.TextInputLayout">
<com.hul.humarashop.CustomFontTextView.EditTextGothamBook
android:id="#+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#00000000"
android:hint="Name"
android:padding="10dp"
android:singleLine="true"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="15sp"></com.hul.humarashop.CustomFontTextView.EditTextGothamBook>
</android.support.design.widget.TextInputLayout>
Set the app:hint="Name" on the TextInputLayout, rather than the EditText.
Just to note as well - you might like to know that the TextInputLayout has a getEditText() method! This means you only have to use one id in the xml, tidying up the code a little.
I had an issue with setting hint in Arabic language. Please refer Alternating edit text hint not visible for Arabic language
for details. The issue was with the use of inputType in the xml. I have removed it and now a normal keypad appears onclick of the edittext field. But I want the user to enter numbers only and I want numerical keypad to appear. How to do it?
In short, the use of inputType will not display the Arabic content and if it is not used then I am getting alphabetical keypad.
Please help, thanks in advance
hope you can use this property android:numeric="integer" and please remove singleline property if you are using it.
<EditText
android:id="#+id/et_account_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:cursorVisible="true"
android:gravity="right"
android:hint="#string/hint_account_no"
android:imeOptions="actionNext"
android:numeric="integer"
android:maxLength="12"
android:textColor="#android:color/black"
android:textSize="20sp"
android:padding="#dimen/edittext_padding">
</EditText>
Use android:inputType="number" or android:inputType="phone" it should give you numeric keypad on click of edit text:
Following is the snippet from my xml, this should help:
<EditText
android:layout_gravity="start"
android:textAlignment="viewStart"
android:hint="my hint"
android:inputType="phone"
android:id="#+id/Nummm"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:textDirection="rtl"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:background="#android:color/transparent"
android:textColorHint="#767676"
android:backgroundTint="#android:color/transparent"
android:layout_height="fill_parent"
tools:ignore="RtlCompat" />