EditText hint doesn't show - android

My EditText configured as follows won't show the hint:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:hint="The hint..."
android:scrollHorizontally="true"
android:singleLine="true" />
It works if I set android:gravity="left" or if I remove android:scrollHorizontally and android:singleLine attributes, which is not desirable. Any suggestions?

using android:ellipsize="end" fixed it for me
Weird bug !! (but Android has a lot of these weirdo bug)

In Lollipop version the default text and hint text color is white for EditText.
So we have to change like this in EditText
android:textColorHint="#color/grey"

I wanted my single-line EditText box to scroll but keep the hint on the right also.
I had the same issue and got the hint to stick by keeping gravity="right", and setting singleLine="true" and ellipsize="end".

You need to give text color to hint
android:textColorHint="#000000"

No need of android:scrollHorizontally attribute. Remove it.EditText is a fixed item on the screen. we want scroll the layout contains the EditText is enough. that is the best design too. you have put android:ellipsize="end" instead of android:scrollHorizontally.

Using android:ellipsize="end" resolves the obvious platform bug. Unfortunately, Xperias still misbehave :(
I found no other solution than to:
if (android.os.Build.MANUFACTURER.matches(".*[Ss]ony.*"))
editText.setGravity(Gravity.LEFT);
else
editText.setGravity(Gravity.CENTER);

The below worked for me:
<EditText
android:id="#+id/UserText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/UserPassword"
android:layout_marginTop="85dp"
android:ems="10"
android:hint="#string/UserHint"
android:inputType="textPersonName"
android:singleLine="true"
android:text="#string/UserName" >
<requestFocus />
</EditText>

This is how, I did for by EditText to have hint in it.
<EditText
android:id="#+id/productQuantity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right|center_vertical"
android:hint="#string/quantity"
android:inputType="numberSigned"
android:ellipsize="end"
android:singleLine="true" >
</EditText>

Try changing the hint text color, sometimes the hint color is the same as the background color
android:textColorHint="#color/colorBlack"

I changed the style to "#style/Base.WidgetMaterialComponents.TextImputEditText". For me it wasn't gravity or color.

Related

how to fix the size of multiline edit text

I want to make a multi line edit text but the problem is that whenever i enter new line height of edit text increases. how to fix its height. My code is
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentBottom="true"
android:layout_marginBottom="60dp"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginTop="10dp"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:padding="10dp"
android:gravity="top">
<requestFocus />
</EditText>
To fix the size of editText you can use
android:singleLine="true"
but it can limit your editText line to 1 .
if you want more lines in editText then use the following property.
Use android:lines="3" .
Use android:lines="2" for fixing multilines and for fixing single line use android:singleLine="true"
for example use like this as shown for multilines
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:lines="2"// fix the multiline limit
android:textColor="#000000" />
for example use like this as shown for single line
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:singleLine="true"// fix the single line limit
android:textColor="#000000" />
try this;
android:inputType="textMultiLine"
<EditText
android:inputType="textMultiLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
As singleline is now deprecated use inputType:multiline and set the number of lines you want with lines tag
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="4"/>
I had a similar requirement but ended up not changing the size of the box. i.e it grows as text is typed into it but stops short of blocking the other widgets in view. I read this post during my quest and had found a solution. Decided to post it back here. Restricting size to a value may possibly have different effects on different screens. So I think it is better to let it be.
The thing is to put the edit text inside a linearlayout with the rest of the widgets. The code and snapshot are here
Multi line edit box with ok cancel buttons

How do I center the hint text within an EditText in Android?

I need to center the Hint text within an EditText in Android. How do I do this?
In order for centering of hint text to work with EditText you have to make sure android:ellipsize="start" is defined. I don't know why this makes it work, but it does.
Example pulled from personal code:
<EditText
android:id="#+id/player2Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="start"
android:gravity="center_horizontal"
android:hint="#string/player2_name"
android:inputType="textCapWords|textPersonName"
android:singleLine="true" />
Actually, android:gravity="center_horizontal" creates the centering effect you're looking for. Similarly, you can use android:gravity="start" to put hint text at the beginning of the EditText view, and so on.
Use this xml attribute:
android:gravity="center"
use attribute
android:gravity="center"
I used this code in every circumstances, and it works perfectly without using android:ellipsize="start" to make a hint in center.
<EditText
android:id="#+id/player2Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:hint="robi"
android:inputType="text" />
I think the answer should be :
android:textAlignment="center"
textAlignment worked for me.
textAlignment="center"
Unfortunately, neither answer helped me aligning hint, written in LTR language, while the layout orientation was RTL. I needed such layout in a kind of translation application to make overlay icons not interfere with RTL text. But this trick didn't work with hints while there was no any text yet (icons appeared above the hint) and I came to the following java solution to layout problem:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
. . .
if (isRightToLeft()){
EditText guess = (EditText) rootView.findViewById(android.R.id.text1);
CharSequence hint = "\u200F" + guess.getHint();
guess.setHint(hint);
}
. . .
}
The trick was in right-to-left mark to prepend a left-to-right string. And it seems to work, but does anyone know a more elegant solution?
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="ENTER PIN"
android:inputType="numberPassword" />
</android.support.design.widget.TextInputLayout>
Note: in the tag TextInputEditText,the property
android:gravity="center"
is what makes the deal of aligning the text in the center including the hint text
use this: android:gravity="center"
I use this and worked for me
android:gravity="Left|center_vertical"
use android:textAlignment="center" in EditText , it work for me
This worked for me:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/nombreslayoutinput">
<EditText
android:id="#+id/nombreslayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/nombres"
android:layout_centerInParent="true"
android:gravity="center|center_vertical"
android:ellipsize="start"
android:inputType="textCapWords|textPersonName"
/>
</android.support.design.widget.TextInputLayout>
The correct answer is
android:gravity="center_horizontal
hint gravity
android:textAlignment="center"
text gravity
android:gravity="left"
My problem was that the EditText wasn't big enought to fit exactly inside its parent (FrameLayout in my case), so using just android:gravity="center" (center_vertical, horizontal, start, or whatever) would just fit it inside the EditText, and not in its parent, so I had to center the EditText inside its parent using:
android:layout_gravity="center"
pd: I used android:background="#android:color/transparent" to hide the ugly underline in the EditText hint

How to add hint into EditText with inputType="numberDecimal"?

I have an EditText like below:
<EditText
android:id="#+id/et_sum"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#android:drawable/editbox_background"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
android:hint="Enter sum" />
But the hint is not displayed. Is it possible to display the EditText hint with inputType="numberDecimal" or not?
you can use
android:ellipsize="start"
to make the hint displayed with an inputtype and gravity
It appears to be a problem with using android:gravity="center_horizontal". Try removing that line as it made the hint appear for me.
Here is one of my EditText tags to compare with:
<EditText
android:id="#+id/txtNumbText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:inputType="numberDecimal"
android:singleLine="true"
android:hint="Number Hint Text">
</EditText>
Hi we can not use Gravity attribute and inputtype="number" attribute at a time so better to neglect gravity attribute.
if u want set hint in middle of edit text use like this : android:hint=" hint "
give space in hint text
<EditText android:id="#+id/xEt" android:layout_width="170dip"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:inputType="number"
android:hint=" numbers only "
android:layout_alignParentRight="true" />

How can I make my EditText five lines high without using android:inputType="textMultiLine"?

I want to have a EditText view that is five lines high. I want it five lines high for visual appeal reasons only (so that it does not appear cramped). The code below does not work, the EditText appears only one line high.
I have tried multilinetext and it works visually, however I want to abandon it as I want the virtual keyboard to say "Next" (rather than have the enter key that is automatically provided with multiline text)
How can I make my EditText box bigger? Alternatively, how can I use the imeOption "actionNext" with multiline text?
This code does not work...
<EditText
android:id="#+id/etEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="text"
android:lines="5" //this has no effect!
android:imeOptions="actionNext"
style="#style/dialogInput" />
Change:
android:inputType="text"
to:
android:inputType="textMultiLine"
Works for me!
<EditText
android:id="#+id/etEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="text"
android:lines="5" //this has no effect!
android:imeOptions="actionNext"
style="#style/dialogInput"
android:singleLine="false" />
android:singleLine="false" will make editText to support multiple lines
On the other hand, you can try to use a line-break on text string to display, this is the tip: http://xjaphx.wordpress.com/2011/07/15/set-line-break-in-textview/
and of course, you must set:
android:singleLine="false"
Change:
android:inputType="text"
To:
android:inputType="textImeMultiLine"
If that doesn't work then change:
android:inputType="text"
To:
android:inputType="textMultiLine"
and delete:
android:imeOptions="actionNext"
style="#style/dialogInput"

EditText with long default text on a single line

I have an EditText that I am trying to set with a very long, unbreaking text value (a URL), but even with the following XML declaration, the text is breaking to a second line.
<EditText
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:maxLines="1"
android:hint="Enter URL"
android:text="http://www.example.com/news/2010-07-15/this-is-the-story-title-here.html">
</EditText>
I've tried the solutions here (adding android:ellipsize="end"), but it made no difference. Reducing the text in length to something no more than the length of the EditText worked... but this is realistic for a URL EditText.
Any suggestions?
Thanks,
Paul
Set
android:scrollHorizontally="true"
Have you tried adding android:singleLine="true" to the mix
<EditText
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:singleLine="true"
android:maxLines="1"
android:hint="Enter URL"
android:text="http://www.example.com/news/2010-07-15/this-is-the-story-title-here.html">
</EditText>
Use value for the attribute inputType other than textMultiLine. The attribute singleLine is deprecated.

Categories

Resources