TextInputLayout hint is not visible in nexus - android

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.

Related

Hint Text is overlapping to my TextInputLayout

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!

Android: TextInputLayout always leaves some space from top

I have this layout:
<LinearLayout
android:id="#+id/dialogCentralContent"
android:gravity="center_horizontal"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_below="#+id/phoneNumberInfo"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:background="#drawable/edittext_white_rounded">
<EditText
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="center"
android:maxLines="1"
android:inputType="none"
android:focusable="false"
android:text="#={dataContext.phonePrefix}"
style="#style/Widget.App.PurchaseAmountEditText" />
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
tools:errorEnabled="true"
app:errorText="#{dataContext.validator.phoneValidation}">
<android.support.design.widget.TextInputEditText
android:layout_height="60dp"
android:layout_width="match_parent"
android:gravity="center"
android:maxLines="1"
android:inputType="phone"
android:text="#={dataContext.phoneNumber}"
style="#style/Widget.App.PurchaseAmountEditText" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
It looks like this:
As you can see the second EditText is rendered lower than the first one. When I look at it in the visual editor of Android Studio I can see that the TextInputLayout has some free space at its top, however setting paddingTop="0dp" didn't change anything. So how to make those two EditTexts render the same way?
By default, android.support.design.widget.TextInputLayout will leave room at the top for the floating hint text. If you're not using the floating hint, you can remove that space by adding the following to the opening <TextInputLayout> element.
app:hintEnabled="false"
The regular hint text will still be visible on the TextInputEditText when it's empty.
N.B. – This answer does not apply to the current Material Components version, which is markedly different than the original.

How to make Edit Text hint appear when typing

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'

Positioning hint within multiline EditText - TextInputLayout

I have an EditText that has 4 lines (min=4; >4 scrolls). The EditText is embedded in a TextInputLayout. The hint displayed for this seems to be centered vertically. I'd like it at the start of the 1st line, naturally.
Important Edit: Testing without TextInputLayout allows for the hint to be positioned effectively. The problem lies with this. Any insight into how to resolve it is appreciated.
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true">
<EditText
android:id="#+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:fadeScrollbars="false"
android:gravity="left"
android:hint="What's going on?"
android:inputType="textMultiLine"
android:lines="4"
android:minLines="4"
android:scrollbarStyle="outsideInset"
android:scrollbarThumbVertical="#drawable/custom_scrollbar_style"
android:scrollbars="vertical"
android:textColorHint="#color/black_semi_transparent" />
<TextView
android:id="#+id/text_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="140"
android:textColor="#color/black_semi_transparent" />
</android.support.design.widget.TextInputLayout>
This bug has been fixed in the v23 support libraries:
https://code.google.com/p/android/issues/detail?id=179720

Can't focus EditText

I have a simple EditText inside my scrollview.
All the other elements are working just fine, however i won't get the usual EditText behaviour on click (Keyboard doesn't appear, I can't write).
Here's my xml for the field.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/enterWishprice"
android:background="#drawable/edit_back"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="0 F€"
android:gravity="center_vertical|center_horizontal"
android:textSize="26dp"
android:inputType="number"
android:layout_margin="10dp" />
As you can see I already tried setting focusable/inTouchMode.
I also tried setting a click listener on the field to manually open the keyboard which works just fine. However I still can't type anything into the field.
After that i tried using requestFocus in the clicklistener without any result.
Furthermore I tried clearFocus on the EditText as well as the surrounding ScrollView - also not working.
Hopefully you can give me a hint cause I'm out of ideas..
Thanks in advance!
The attribute Enabled must be set to true.
<EditText
android:id="#+id/room_message"
android:layout_width="164dp"
android:layout_height="46dp"
android:clickable="true"
android:ems="10"
android:enabled="true"
android:focusableInTouchMode="true"
android:hint="#string/prompt_message"
android:inputType="textPersonName"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="italic"
/>
But i have got another problem where the EditText won't lose focus....
try like this
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/enterWishprice"
android:background="#drawable/edit_back"
android:focusableInTouchMode="true"
android:text="0 F€"
android:gravity="center_vertical|center_horizontal"
android:textSize="26dp"
android:inputType="number"
android:layout_margin="10dp">
<requestFocus />
</EditText>

Categories

Resources