So I'm currently facing a bug on android, where if I set, for an EditText, a gravity to "center", an inputType and a hint, the hint is not displayed. I've tried multiple advices, like adding `singleLine="true", an ellipsize parameter, or a few others, with multiple combinations of these, but to no effect. I can only manage to get either my field not centered with a hint, or centered but without a hint.
The trade-off I currently use (no inputType):
<EditText
android:id="#+id/view_email"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="12dp"
android:layout_weight="1"
android:paddingTop="7dp"
android:paddingBottom="7dp"
android:gravity="center"
android:maxLines="1"
android:ellipsize="start"
android:hint="#string/email_placeholder"
android:background="#ffffff"
android:imeOptions="flagNoExtractUi"/>
Apparently it's a known bug, but I couldn't find any workaround that actually worked in my case. I just try to have an EditText for an input of type "email", with a centered hint.
Has anyone come with a workaround that actually works for this? I found out that it's quite a PITA for users to enter an email when the input type is not set to email.
This worked for me, give it a try
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:digits="0123456789.,"
android:ellipsize="start"
android:maxLines="1"
android:gravity="center"
android:background="#ffffff"
android:hint="#string/email_placeholder">
</EditText>
perhaps you could use this as a workaround: https://github.com/malmstein/FloatingHints
<EditText
android:id="#+id/view_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_weight="1"
android:paddingTop="7dp"
android:paddingBottom="7dp"
android:gravity="center"
android:maxLines="1"
android:ellipsize="start"
android:hint="#string/email_placeholder"
android:background="#ffffff"
android:imeOptions="flagNoExtractUi"/>
This works for me. just changed the height attribute
Related
I want to set the hint of my AutocompleteTextView in a single line with extra string to be truncated with dots(...) in the end.
I am using singleLine="true", maxLines="1", ellipsize="end".
But still the hint is shown in two lines. Although The text is set to single line. But I need the hint should also need to shown in single line.
The Preview in Android Studio shows the hint in single line. But when I run it on Device it shows in 2 lines.(S5, Nexus-5, Nexus-6, J7).
I also want the imeOption should be always search. i.e. imeOptions="actionSearch" Hence I can't change it to actionNext.
Below is my XML Code:
<RelativeLayout
android:id="#+id/liLaySearchMap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:paddingLeft="10dp"
android:background="#color/cococo"
android:paddingRight="10dp">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/five_dp"
android:background="#color/white"
android:padding="#dimen/two_dp"
android:scrollHorizontally="true"
android:drawablePadding="#dimen/two_dp"
android:singleLine="true"
android:lines="1"
android:maxLines="1"
android:ellipsize="end"
android:textSize="#dimen/twelve_sp"
android:drawableLeft="#drawable/ic_action_search"
android:inputType="text"
android:hint="A Very Long Hint Text Which Need To Be Tuncated At the End In Single Line"
android:id="#+id/edSearch"
android:imeOptions="actionSearch"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/tvCancel"
/>
<TextView
android:id="#+id/tvCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:layout_margin="#dimen/five_dp"
android:text="#string/cancel"
android:textSize="#dimen/twelve_sp"
android:textColor="#color/tw__composer_red"
android:padding="#dimen/five_dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
Can Anyone Please en-curtain the issue I am facing. As I think I had used every possible solution but still the hint is not in single line.
these are screenshots on my Device and xml i tried is as follows
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/white"
android:padding="2dp"
android:scrollHorizontally="true"
android:drawablePadding="2dp"
android:singleLine="true"
android:lines="1"
android:maxLines="1"
android:ellipsize="end"
android:textSize="16sp"
android:inputType="text"
android:drawableLeft="#mipmap/ic_launcher"
android:hint="A Very Long Hint Text Which Need To Be Tuncated At the End In Single Line"
android:id="#+id/edSearch"
android:imeOptions="actionSearch"/>
try Setting android:inputType="text" on the AutoCompleteTextView it worked for me
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text"
android:ellipsize="end"
android:imeOptions="actionNext"
android:hint="this is to check if it's getting truncated and in single line or not"/>
Setting android:inputType="text" on the AutoCompleteTextView it worked for me, unlike android:ellipsize="end", the text did not stay with '...' on end, but it does meet expectations.
android:completionThreshold="1"
WHAT I HAVE
I have a TextView who is showing a URL with "https://" prefix:
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="test2"
android:maxLines="1"
android:ellipsize="marquee"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#color/primary_text"
android:id="#+id/txvNomEntornIversio" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="https://test2.sdasasdasdfasdfasdffasdfasdfasdf.sdffd"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="10dp"
android:textSize="13sp"
android:textStyle="italic"
android:id="#+id/txvUrlEntorn"/>
</LinearLayout>
WHAT IS THE PROBLEM?
The result in android studio preview and in device after execute the code was:
If execute previous code:
If I remove the "/" symbols:
If I move the symbol in other position:
WHAT I NEED
I need to show the prefix "https: //" with maximum letters to fit the available space.
WHAT I TRIED
I tried to read documentation (setEllipsize block) and search in stackoverflow, searching for some reference with this symbol and nothing found.
I tried also to scape the symbols with no effect.
Anyone know why it occurs and can help me? Thanks in advance!
UPDATED LAYOUT
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/icon_unchecked"
android:layout_marginRight="10dp"
android:id="#+id/txvIconChecked"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="test2"
android:maxLines="1"
android:ellipsize="marquee"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#color/primary_text"
android:id="#+id/txvNomEntornIversio" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="https://mydomain.asdfasdasdfasdfasdffasdfasdfasdf.cat"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="10dp"
android:textSize="13sp"
android:textStyle="italic"
android:id="#+id/txvUrlEntorn"/>
</LinearLayout>
</LinearLayout>
UPDATE 2
Thanks to Teiky, we have found that this problem occurs only in versions lower than API 23. It may be a bug?
The option (deprecated) Android: SingleLine = "true" seems to work correctly in all versions! Instead, the new option android: MaxLines with android: ellipsize only works for 23 ...
At the moment, the most viable option seems to ignore deprecated SingleLine ...
SOLUTION FOR ME
Finally, as I said in the last update, my solution was to continue using android: SingleLine = true even if it is marked as deprecated.
Teikyo seconds, he tried a dipsositiu android 4.4.4 and worked well using MaxLines ellipsize ... and me, a device Lollipop I still cut the text to find the symbol / ...
Set in response Teikyo as good as it helped me to investigate the problem further. Thank you all for your help!
I tried your code and the URL is fully display.
Maybe you should check these parameters, if you have enough width to display the complete URL:
android:layout_width="0dp"
android:layout_weight="1"
UPDATE by xikitidistant:
The solution isn't the weight and width="0dp". This was a code improve. The solution for me is updated in the question. Thanks for your help.
android:maxLines="1"
android:ellipsize="end"
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 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>
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