I have 2 multi line EditText with 2 lines of text entered as shown in images below.
Edittext 1:
<EditText
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="50dp"
android:paddingStart="10dp"
android:background="#ffffff"
android:includeFontPadding="false"
android:paddingEnd="10dp"
android:maxLines="1"
android:inputType="textMultiLine|textNoSuggestions"/>
EditText 2:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:paddingStart="10dp"
android:background="#ffffff"
android:includeFontPadding="true"
android:paddingEnd="10dp"
android:maxLines="1"
android:inputType="textMultiLine|textNoSuggestions"/>
I have two questions..
The first EditText has fixed height 30dp and contains a fixed space above line "ASDFGHJKL...". How can i get the value of this space?
Secondly, how can i get the value of fontpadding, when android:includeFontPadding is set to true.?
#DevMarc
Question 1:
Idea is Android has options to have multi line text views, it seems you have forced it to be single line.
android:maxLines="1"
Please try using something like this:
android:lines="2"
Ref: Android Developer Site for Multiple Lines
If you interested in adding ellipses use this:
android:ellipsize="1"
Ref: Please find the link in comments as with my profile can't post more than two links.
Question 2
Try this :
textview.getPaint().getFontSpacing()
Ref: Get Paint method for textview
Hope it helps.
Related
I'm working on a TextView which is contained in a ConstraintLayout.
I want ellipsize to add three dots at the end of text(in the TextView) if its length exceeds maxLength.
maxLines="1" and ellipsize="end" seemed to the best answer after a thorough research about my question. Unfortunately, it didn't work for my case. The three dots did't show at all.
Here's the snapshot :
The original string was "Test for long description"(The n was dropped). It's supposed to show "Test for long descrip...".
Here's my xml :
<TextView
android:id="#+id/txtDescription"
android:maxLength="24"
android:maxLines="1"
android:ellipsize="end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="120dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:text="DescriptionView"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.72" />
I feel like there's something override ellipsize in the XML, or did I miss something crucial in the XML file?
The problem is:
android:maxLength="24"
remove it since you want the TextView to be ellipsized.
A TextView gets ellipsized when it is not wide enough to show the whole text. I think you do not understand what this attribute android:ellipsize="end" is all about. If it is wide enough then you will not see any dots at the end because they are not needed.
If you set android:layout_width="40dp" then you will see the dots.
With android:layout_width="wrap_content" the TextView is wide enough and it is not ellipsized.
1) Add one more property android:singleLine="true" in your Textview
(But its Deprecated so use second option)
2) Use this three together
android:maxLines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
Ellipsize is quite a pain in android, apply below on your textView :
txtDescription.setSingleLine(true);
Hope it helps.
The key for making three dots shows is constrain the width of the text view.
Suppose the name of image in your posted figure is left_image,
change the xml attributes of TextView as below:
....
android:layout_width="0dp"
app:layout_constraintStart_toEndOf="#+id/left_image"
....
above two lines make the width of TextView is constrainted(between left img and right border of parent).
In my case following line was the problem. I commented it out and it worked.
<item name="android:inputType">text|textNoSuggestions</item>
To fix this, you need to use a fixed width for the textview instead of maxLength attribute in your xml
In xml :
android:maxLines="1"
android:ellipsize="end"
And in java/kotlin program :[Important]
textDescription.setSelected(true) -> Java
or
textDescription.isSelected=true -> Kotlin
I have this stupid and seemingly trivial problem with the properties of an EditText.
The properties I am trying to achieve for the EditText, are the following:
The contents of the view should NOT contain newlines. It can be text, numbers, symbols, but no newlines.
The soft keyboard should NOT display the enter button because of the above. It should instead display something like "Send" or "Done".
The contents of the view should NOT continue horizontally when reaching the edge of the screen. Instead I want to wrap the text, displaying it on multiple lines.
I have tried many different combinations, but I can not achieve this combination.
What I currently have is this, which is inside a RelativeLayout:
<EditText
android:id="#+id/comment_box"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_below="#id/preparation_text"
android:hint="#string/comment_hint"
android:inputType="textCapSentences|textAutoCorrect|text"
android:scrollHorizontally="false"
android:maxLength="400"
android:imeOptions="actionSend"/>
It achieves 2 of 3. No newlines possible, keyboard displays "Send" rather than the enter-key for me, but the text continues on one line.
Changing inputType="text" to "textMultiLine" wraps text correctly on multiple lines, but also overrides the keyboard to always display the enter button.
I have tried different solutions around the Internet, including setting the properties maxLines="4", singleLine="true" and possible others that I have forgotten again.
I can not find a combination that works.
Output:
Exp:
The op is on right track. I did some research found that some options gets ignored which are specified in XML. but if the same options are set in code then it should do the trick. I used the same XML fragment specified in the question.
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="80dp"
android:hint="hint"
android:inputType="textCapSentences|textAutoCorrect|text"
android:scrollHorizontally="false"
android:maxLength="400"
android:imeOptions="actionSend"
/>
And by adding the following lines in the code, it helped in achieving what you want.
edit_text.setMaxLines(Integer.MAX_VALUE);
edit_text.setHorizontallyScrolling(false);
textShortMessage is the inputType that you are looking for:
<EditText
android:id="#+id/commentEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:gravity="left"
android:text=""
android:hint="hint"
android:textSize="16dp"
android:textColor="#android:color/black"
android:lineSpacingExtra="0dp"
android:lineSpacingMultiplier="1"
android:background="#android:color/white"
android:selectAllOnFocus="true"
android:inputType="textShortMessage|textMultiLine|textCapSentences"
android:singleLine="false" />
Refere to this to prevent paste function. To prevent pasting a new line.
Please use android:imeOptions="actionSend"
to solve your problem.
I have the same issue a long time ago, you have to programmatically change Edittext property on OnCreate().
So in XML, create your Edittext like this
<EditText
android:id="#+id/comment_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="80dp"
android:hint="Comment here"
android:maxLength="400"
android:inputType="textMultiLine" />
And on onCreate() (I wrote in kotlin not Java)
comment_box.imeOptions = EditorInfo.IME_ACTION_SEND
comment_box.setRawInputType(InputType.TYPE_CLASS_TEXT)
I want create simple calculator for android, and having problem with displaying long equations. Everything is OK (one line, horizontal scrolling), but I don't see end of line (always see start of line). Would it be possible to scroll it automatically to the latest character?
Example:
Hello there
...lo there
--------
-
<EditText
android:id="#+id/etDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:clickable="false"
android:cursorVisible="false"
android:ems="10"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="right"
android:textSize="15sp"
android:scrollHorizontally="true"
android:singleLine="true"
android:ellipsize="end"
android:hint="0." />
Image: SimpleCalc image
Try this one:
EditText editText = (EditText) findViewById(R.id.editText1);
editText.setSelection(editText.getText().length());
The "official" way of doing that is (as suggested in the comments), via the ellipsize attribute set to end. If it's not working, it might be due this attribute is a bit tricky, meaning that it has some circumstances to be happening in order to work (like for example, singleLine=true).
You might want to see this, it helped me when I had this issue.
I'm trying to make a text box about 3 lines high but also the textbox will also expand depending on the amount of information entered. I've used wrap_content which displays as one line and I've used android:layout_height="150dp", however the text box does not expand. Any guidance would be much appreciated.
<EditText
android:id="#+id/editEmailCompose"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/editEmailSubject"
android:layout_toRightOf="#+id/textSubject"
android:ems="10"
android:gravity="top|left"
android:layout_marginRight="20dp"
android:hint="#string/emailCompose" />
Ok so I found the code required. It may help others.
*android:layout_height="wrap_content"
android:isScrollContainer="true"
android:minHeight="120dp"
android:inputType="textMultiLine"*
I'm using a TextView in Android, what I want to show 1 line in TextView ending with ". " but this give [] type box at the end. I don't know why? I just want to remvoe this box and only to show text ending with "... "
Update code for the list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="85dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:cacheColorHint="#4C7B8D"
android:background="#4C7B8D">
<ImageView
android:id="#+id/videoListImage"
android:src="#drawable/audio_thumbnail60x60"
android:layout_height="75dp"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:layout_width="75dp"
android:padding="4dp"
android:background="#color/light_gray" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/next_arrow"
android:orientation="vertical"
android:gravity="center_vertical"
android:paddingLeft = "5dp">
<TextView
android:id="#+id/row_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#color/app_background_color"
android:textSize="18sp"
android:ellipsize="end"
android:maxLines="1" />
<TextView
android:id="#+id/row_dis"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#color/color_black"
android:layout_marginRight="2dp"
android:textSize="15sp"
android:ellipsize="end"
android:maxLines="1" />
<TextView
android:text="$7.50"
android:id="#+id/audio_price_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:textColor="#color/color_white"
android:textStyle = "bold"
android:paddingLeft = "12dp"
android:paddingRight = "12dp"
android:background="#drawable/blue_round_cornor_background" />
</LinearLayout>
<ImageView
android:id="#+id/next_arrow"
android:src="#drawable/next_arrow"
android:layout_toLeftOf="#+id/saved_purchased"
android:scaleType="fitXY"
android:layout_height="25dp"
android:layout_width="18dp"
android:layout_centerVertical="true"
android:visibility = "gone"/>
<ImageView
android:id="#+id/saved_purchased"
android:layout_alignParentRight="true"
android:layout_alignParentTop ="true"
android:scaleType="fitXY"
android:layout_height="25dp"
android:layout_width="25dp"
android:layout_marginRight="2dp"/>
</RelativeLayout>
Here is the images of "next_arrow"
Here is the code I am using the getView() in adapter.
String discription = listData.getDescription();
if (discription != null && discription.length() > 0) {
if (textViewDis != null) {
textViewDis.setTypeface(titleFont);
Log.e("data", ""+discription);
discription.replaceAll("\r\n", "");
textViewDis.setText(discription);
}
}
Here is the actual String of description to be display.
Andrew and Stephanie Tidwell candidly share their success story in this business. This story will help everyone listening realize that no one is perfect, even in a second generation business. This is a streaming audio file.
Still have some issue? I can update question more.
Quoting myself from one of my books:
Android's TextView class has the built-in ability to "ellipsize" text,
truncating it and adding an ellipsis if the text is longer than the available
space. You can use this via the android:ellipsize attribute, for example.
This works fairly well, at least for single-line text.
The ellipsis that Android uses is not three periods. Rather it uses an actual
ellipsis character, where the three dots are contained in a single glyph.
Hence, any font that you use that you also use the "ellipsizing" feature will
need the ellipsis glyph.
Beyond that, though, Android pads out the string that gets rendered on-screen, such that the length (in characters) is the same before and after
"ellipsizing". To make this work, Android replaces one character with the
ellipsis, and replaces all other removed characters with the Unicode
character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF). This means the
"extra" characters after the ellipsis do not take up any visible space on
screen, yet they can be part of the string.
However, this means any custom fonts you use for TextView widgets that
you use with android:ellipsize must also support this special Unicode
character. Not all fonts do, and you will get artifacts in the on-screen
representation of your shortened strings if your font lacks this character
(e.g., rogue X's appear at the end of the line).
I have bumped into the same problem when was trying to use custom "MetaPro-Medium.otf" as font for TextView with a
android:singleLine="true".
The box at the end of the string was really annoying.
I found no way how to solve this problem in Android, but at the same time found following work around.
I have installed "FontLab Studio v5.04"
Opened my font
Selected one of symbols I was not going to use
Menu->Glyph->Rename Glyph
Changed the name and unicode index from it`s original value to "FEFF" (Thank CommonsWare)
Double click on selected symbol and then remove all lines this symbol was created from.
Menu->File->Generate Font->save as type otf
As a result I got updated font and problem gone away.
Arslan, your layout is working fine in my case, I have tested the same with:
<TextView
android:id="#+id/row_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="18sp"
android:ellipsize="end"
android:maxLines="1"
android:text="This is the demo testing demo testing This is the demo testing demo testing"/>
... and getting the exact output as you want "one line ended with ..." and box should be removed. So I think there may be a something wrong with any character or text you are setting.
I face the same issue (show boxes([])) for some special symbols when I try to show content which is coming from webservice url even, I don't use android:ellipsize. then I replace code from
textview.settext(content);
to
textview.settext(Html.fromHtml(content));
working fine.
Actually I was running into this issue and instead of changing the font or using setText I just added scrollHorizontally as false and it fixed the extra box character
android:singleLine="true"
android:scrollHorizontally="false"
android:ellipsize="end"
There was a similar problem which i was facing in my project where in i was using a font type for the text view. few font types have these problem of making the ... appear as [] at the last. The problem would be solved if u try changing the font.