Remove next line visibility in multiline Edittext android - java

I have a Multiline Edittext of fixed height, 30dp. I need to show only a single line at once. But when user enters multiple lines and scrolls up, user can see some part of the next line (as shown in image 2). It should not happen. I need only one line with the top and bottom spacing like in image 1 without removing the multiline feature.
<EditText
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="50dp"
android:background="#ffffff"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:maxLines="1"
android:inputType="textMultiLine|textNoSuggestions"/>

This [almost] appears okay to me:
<EditText
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="50dp"
android:background="#ffffff"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:maxLines="1"
android:gravity="bottom"
android:inputType="textMultiLine|textNoSuggestions"/>

If you want to allow user to see only last line of text, you can do following:
use single line input
if user enters "\n", store current text somewhere, and clear text in input
You should be able to do it e.g. with InputFilter or
onKeyDown()

Related

How to break lines at a given character if the text is forced to wrap in your textview? (android)

So I have my textview's height set to wrap content. It displays a sports score in the format
"CHI 99 CHA 88". I have the textview match the parent for its width. I also have the score text set to a specific textsize in "sp" units.
So on smaller phones, if there are more characters in the score, or if font size (accessibility settings) is changed, there is a chance that the text will need to wrap into 2 lines. However, I would like a way to control where (in the string) it will decide to wrap the text and make a new line. It would look best in the form
"CHI 99\nCHA 88". But I prefer the text to be on the same line unless it is forced to wrap by screen size, character count, or accessibility settings, so I don't want to hardcode in a "\n" from the beginning.
So basically, is there a way to control what character the text decides to create a new line at if there is a necessity for the text to wrap onto a new line.
Thanks for any responses!
Instead of programatically calculating display sizes/characters, etc., Flow widget with two TextViews can be used control this.
An example layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="150dp"
android:layout_height="match_parent">
<androidx.constraintlayout.helper.widget.Flow
android:layout_width="0dp"
android:layout_height="wrap_content"
app:constraint_referenced_ids="text1,text2"
app:flow_horizontalBias="0"
app:flow_horizontalGap="5dp"
app:flow_horizontalStyle="packed"
app:flow_wrapMode="chain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHI 99" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHA 88" />
</androidx.constraintlayout.widget.ConstraintLayout>
Normally, with default sizing, it looks like this:
If the views cannot fit horizontally, second TextView moves to the next line:
you can avoid line breaks by use autosize and set maxLines to 1 like this:
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeStepGranularity="2sp"
android:maxLines="1" />
Source: https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview
You can calculate characters in one line according to screen width and add new line character after that.

EditText Accept Numbers between two numbers

I have edit text view in my layout like below. I am able to set digits to accept but I want set limit to accept between two numbers like 1 to 100 from java. I am not able to get idea how I can achieve this. My edittext is like below
<EditText
android:id="#+id/userInputDialog"
android:layout_marginTop="20dp"
android:layout_below="#+id/dialogueError"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="120"
android:textStyle="bold"
android:digits="0123456789"
android:textColorHint="#color/toolbar_text"
android:textColor="#color/toolbar_text"
android:inputType="number" />
Let me know if anyone can help me here for same. Thanks!
You have
android:maxLength="2"
To set it to only 2 chars length.
You can also use
android:inputType="number"
For numbers only

Stop user input from expanding the text field

I want to disallow the user from being able to expand the the text field as shown in the image. It should look like the Password field however both will allow the following to happen with space bar or the return key.
Text field expansion
Set your all padding to something like 2dp then set maxLines to something that wont overlap the text. Maybe 2 or if you only care for 1 line, then set singleLine=true.
Your XML for that TextView can look something like so:
<TextView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:text="Hello World"
android:id="#+id/txtSomeIdForTextView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="false"
android:padding="2dp"
android:textSize="16dp" />
Take a look at this article to get started with UI, old but still good:
https://mobiforge.com/design-development/understanding-user-interface-android-part-1-layouts

Is there anyway I could specify the height of the edit text in Android

I want to know if there is any way I could customize the height of an edit text that I am using. I want it to be something similar to this picture Comment Box
This is my code so far;
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#ffe7e7e7"
android:layout_marginTop="10dp" />
I would like to also know if I could notify the user how much character they have got left to write inside that edit text. So like 100 characters left out of 1000 characters. How can I go about doing this ?
you can define lines attribute
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="5"/>
To keep count, you can add TextWatcher to you EditText
Refer:
How to use the TextWatcher class in Android?
http://developer.android.com/reference/android/text/TextWatcher.html

Horizontal EditText scroll one character at a time

I'm using the following XML attributes for my EditText:
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="#string/edit_message"
android:lines="1"
android:maxLines="1"
android:scrollHorizontally="true"
android:typeface="serif"
Currently, when the text of my EditText becomes longer than it's size, the cursor moves to the beginning, and all of the previous text is backed up out of sight.
When the text of my EditText becomes longer than it's size, a new line begins, and the height of the EditText stays the same.
I want my EditText to scroll similar to the Google search bar; once the text becomes too long, the cursor should remain at the end, and as further characters are typed, the previous text should move backwards only one character at a time.
Here's a video displaying my problem.
Have you looked at the Ellipsize attribute, this solved a similar issue for us. TextViews also have the attribute android:singleLine="true" which is most likely to be what you are missing

Categories

Resources