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
Related
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" />
I am implementing a programming language code editor for the same I need EditText horizontally scrollable also multiline and I want to turn off the autocorrect and the autosuggest. Suppose, I want to write
int main(){
printf("This is an awesome platform! I can get any problem solved here!");
}
then EditText should show in the exact same way. Like shown in the below image
screenshot
Dots at the end of the line denotes that it should be scrollable horizontally.
I tried this
<EditText
android:layout_below="#id/label_code"
android:id="#+id/et_code"
android:layout_width="match_parent"
android:layout_height="400dp"
android:inputType="textNoSuggestions|textMultiline"
android:gravity="top"
android:scrollHorizontally="true"
android:background="#drawable/square_border_unselected"
android:padding="15dp" />
But in that case, horizontal scroll is not working. The text is going to next line if it's length is more than screen size.
Is there any solution to implement all three features in EditText?
Edit #1:
If I don't use textMultiline than I am able to achieve horizontally scrollable EditText
Update #1
This is not the perfect solution but through this I achieved what I wanted.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:minEms="1000"
android:layout_height="wrap_content"
android:minHeight="250dp"
android:inputType="textNoSuggestions|textMultiLine"
android:gravity="top"
android:padding="15dp" />
</HorizontalScrollView>
android:inputType="text" will do the job for you!
<EditText
android:text="This is an awesome platform! I can get any problem solved here!"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#876"
android:imeOptions="actionDone"
android:inputType="text"
android:paddingLeft="2dp"
android:textColor="#FFFFFF"/>
EDIT: Here goes what you want! Horizontal scroll with multi line.
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#876"
android:paddingLeft="2dp"
android:text="This is an awesome platform! I can get any problem solved here!"
android:textColor="#FFFFFF" />
</HorizontalScrollView>
out put:
EDIT3 : This is nothing but because you are lazy.Adjust bounds like below!
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:background="#789"
android:inputType="textMultiLine"
android:layout_width="500dp"
android:layout_height="200dp"
android:textColor="#FFFFFF" />
</LinearLayout>
</HorizontalScrollView>
Cheers!
Try this:
android:scrollbars = "vertical"
in your EditText xml.
try these lines in your edittext
android:inputType="textMultiLine"
android:maxLines="10"
android:scrollbars="vertical"
Try putting your editText in a scroll view
The combination of XML attributes that removed both the Suggestions and the Suggestions Bar while retaining multi-line text was the following:
android:privateImeOptions="nm"
android:inputType="textNoSuggestions | textMultiLine"
or
android:privateImeOptions="nm"
android:inputType="textFilter | textMultiLine"
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'
I'm making a calculator and user input is contained in EditText. Input is typed through buttons on screen, so Android keyboard is disabled. However, I want it to write all input in one line and when line reaches border, it needs to be ellipsized and then horizontally scrollable so you can reach whole text.
I tried doing this by setting android:maxLines="1" and android:ellipsize="end", but that doesn't work. Text is still in multiple lines, but only one line is visible and you need to scroll vertically to see other lines. I also tried using android:singleLine="true", but that makes EditText completely unusable.
This is EditText XML:
<EditText
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp" />
I think this will work for you. Let me know if it works.
<EditText
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp"
android:inputType="text"
android:maxLines="1"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"/>
This post might help you as well.
For single line in EditText, you just need to set two properties:
android:inputType="text"
android:maxLines="1"
Adding this line in the edittext make scrollable singleline text.
android:inputType="textShortMessage"
**This example helps you to create multiline EditText in Android.**
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity"
>
<!--
android:scrollbars="vertical"
It will display a vertical scrollbar if the EditText text exceed
3 lines (android:maxLines).
-->
<EditText
android:id="#+id/et"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:hint="Multiline EditText by XML layout"
android:fontFamily="sans-serif-condensed"
android:background="#d3d7b6"
android:minLines="2"
android:maxLines="3"
android:scrollbars="vertical"
android:inputType="textMultiLine"
/>
<EditText
android:id="#+id/et2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:fontFamily="sans-serif-condensed"
android:hint="Multiline EditText programmatically"
android:background="#d4d7a5"
android:layout_below="#+id/et"
/>
</RelativeLayout>
I have a fairly complex (not really) xml layout file. One of the views is a LinearLayout (v1) with two children: an EditText(v2) and another LinearLayout(v3). The child LinearLayout in turn has an EditText(v4) and an ImageView(v5).
For EditText v2 I have imeOptions as
android:imeOptions="actionNext"
But when I run the app, the keyboard's return does not check to next and I want it to change to next. How do I fix this problem?
Also, when user clicks next, I want focus to go to EditText v4. I do I do this?
For those who really need to see some code:
<LinearLayout
android:id="#+id/do_txt_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/col6"
android:orientation="vertical"
android:visibility="gone" >
<EditText
android:id="#+id/gm_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/coldo_text"
android:hint="#string/enter_title"
android:maxLines="1"
android:imeOptions="actionNext"
android:padding="5dp"
android:textColor="pigc7"
android:textSize="ads2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/rev_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/coldo_text"
android:hint="#string/enter_msg"
android:maxLines="2"
android:padding="5dp"
android:textColor="pigc7"
android:textSize="ads2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="#drawable/colbtn_r”
android:clickable="true"
android:onClick=“clickAct”
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/abcat” />
</LinearLayout>
</LinearLayout>
Just add android:maxLines="1" & android:inputType="text" to your EditText. It will work!! :)
singleLine is deprecated. Adding an input type (eg: android:inputType="text") also worked for me.
Use android:maxLines="1" as singleLine is deprecated
android:singleLine has been deprecated, it is better to combine android:maxLines="1" with android:inputType="text". This would be the code:
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text"
/>
The answers given here were all very helpful, but I was still struggling to get my keyboard's "Next" to show.
Turns out that when you use Android's android:digits attribute in your XML, it prevents the android:imeOptions="actionNext" from working as expected.
The answer is actually to use the deprecated android:singleLine="True". This seems to force the IME Option to be respected.
Old, Non-Working Code
<android.support.design.widget.TextInputEditText
android:id="#+id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- "
android:ellipsize="end"
android:hint="#string/first_name"
android:imeOptions="actionNext"
android:inputType="textCapWords"
android:maxLength="35"
android:maxLines="1" />
Working Code
<android.support.design.widget.TextInputEditText
android:id="#+id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- "
android:ellipsize="end"
android:hint="#string/first_name"
android:imeOptions="actionNext"
android:inputType="textCapWords"
android:maxLength="35"
android:maxLines="1"
android:singleLine="true" />
I'm not a fan of using a deprecated attribute, but for now it seems to get the desired result.
single line deprecated so you add below code I think inputType must.
<EditText
android:inputType="text"
android:maxLines="1"
android:imeOptions="actionNext" />
Finally i have got sure solution for this issue
Just add these 3 lines in your edit text and it will be working fine
android:maxLines="1"
android:inputType="text"
android:imeOptions="actionDone"
Here you can add maxLines according to your requirement. Do not use singleLine as it is deprecated now.
Good luck!
These three lines are enough.
android:singleLine="true"
android:inputType="text"
android:imeOptions="actionNext"
android:inputType="text"
You have to specify an inputType in order for imeOptions to function.
below code is force
android:inputType="text"
Only this worked for me.
Change it:
android:maxLines="1"
android:inputType="text"
android:imeOptions="actionNext"
on that:
android:singleLine="true"
android:inputType="text"
android:imeOptions="actionNext"
Key here is to set input type and imeOptions attributes
<EditText
android:inputType="number"
android:maxLines="1"
android:imeOptions="actionSearch" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/auth_register_re_password"
android:hint="Enter Password Again"
android:imeActionLabel="login"
android:gravity="center"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"/>
Only put in your EditText xml
android:inputType="text"
Add this following lines to in your EditText.
<Edittext
android:layout_height = "match_parent"
android:layout_widht = "match_parent"
android:inputType="text"
android:maxLines="1"
android:imeOptions="actionSearch"
android:imeActionLabel="Search"
android:hint = "Search Here" />