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>
Related
For an application that I'm working on, I have an editText that I allow users to input data into. I have defined padding on the input that is not maintained when multiple lines of text are entered in. For example:
After adding a second line of text:
As more and more lines are added, I'm also seeing that the position of the edittext in the parent view gets lower and lower:
My XML for the editText is as follows:
<EditText
android:id="#+id/message_edit"
android:layout_width="0dp"
android:layout_weight="0.75"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/dp_8"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/someBackground"
android:paddingLeft="#dimen/dp_12"
android:paddingRight="#dimen/dp_3"
android:elevation="3dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="Type here"
android:lineSpacingExtra="#dimen/dp_4"
android:textColor="#color/black"
android:textSize="#dimen/sp_17" />
I assume that both issues are related given but i'm not sure what the underlying cause is.
Instead android:paddingLeft and android:paddingRight use only android:padding to add padding on all side. Check below:
<EditText
android:id="#+id/message_edit"
android:layout_width="0dp"
android:layout_weight="0.75"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/dp_8"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/someBackground"
android:padding="#dimen/dp_12"
android:elevation="3dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="Type here"
android:lineSpacingExtra="#dimen/dp_4"
android:textColor="#color/black"
android:textSize="#dimen/sp_17" />
Result:
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 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"
I have a EditText, where the text is in the middle of the EditText(gravity:center)
But when a line break happens, the text starts from the middle under the text. What I want is that the text shall start from the left when a linebreak happens.
This picture explains what I want to archive: http://oi61.tinypic.com/zycxut.jpg
I have tried all theese: Text-align:Viewstart/textStart, Gravity: Center | left
without any succses.
<EditText
android:id="#+id/edittext"
android:textColor="#000000"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="320dp"
android:editable="true"
android:layout_below="#id/toolbar"
android:layout_marginTop="44dp"
android:singleLine="false"
android:gravity="center"/>
try this,
you can add android:inputType="textMultiLine"
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="320dp"
android:layout_marginTop="44dp"
android:background="#ffffff"
android:editable="true"
android:gravity="center"
android:inputType="textMultiLine"
android:textColor="#000000" />
OK, so by the looks of your picture, it seems that you want the text left justified and starting in the middle of the EditText. There isn't a way to do this directly, but we can make a work around by using 2 EditTexts, each taking up half of the white block in your image, then ignoring the one on the left. This will give the appearance of text starting from the middle, when in reality it starts from the left edge of the right EditText.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="320dp"
android:weightSum="2"
android:orientation="horizontal">
<EditText
android:id="#+id/ignore_this_one"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff"
android:editable="false" />
<EditText
android:id="#+id/put_text_in_here"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff"
android:editable="true"
android:gravity="center_vertical"
android:inputType="textMultiLine"
android:textColor="#000000" />
</LinearLayout>
First, notice how each EditText has a layout_weight of 1. This tells Android that they should each take up an equal amount of space on the screen, making them each take up half.
Second, notice how the second EditText has a gravity_vertical element. This makes it so text is centered vertically, but not horizontally.
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