I am having an issue with my EditText's on a few devices. I have a couple EditText's in an activity. Also, I have the option for the user to resize the font size. When the user selects a large font, then goes back down to a smaller font, the height of the EditText's widgets do not shrink to accomodate the smaller font (extra padding). I have only observed this behavior on a few devices; most work just fine. Any advice? I found this, Resizing TextView does not shrink its height on Android 3.1, which I think may be related, but adding the suggested escape codes does not seem to help. Thanks!
ADDED:
<LinearLayout
android:id="#+id/linearLayout_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
android:background="#drawable/yellow" >
<EditText
android:id="#+id/editText_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:minWidth="#dimen/add_note_min_width"
android:textSize="18dip"
android:background="#fa0"
android:ems="10"
android:hint="#string/title"
android:inputType="text"
android:textStyle="bold" />
<EditText
android:id="#+id/editText_body"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="16dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="0dp"
android:gravity="top"
android:minWidth="#dimen/add_note_min_width"
android:minHeight="#dimen/add_note_min_height"
android:textSize="18dip"
android:background="#af0"
android:ems="10"
android:hint="#string/body"
android:inputType="textMultiLine" />
</LinearLayout>
Here is the xml for the code in question. As I said above, I have tried adding the \u3000, \u2060, and \u200b escape characters to the end of the text (independently) as was suggested in the provided link. Also, I set the bottom EditText to a layout weight of 1 to try to take up the extra padding below the title EditText. I have contemplated trying a manual measure and resize of the EditText, but this seems hacky, especially since this only affects few devices. This seems to be an actual bug with Android, but I couldn't confirm this or find a workaround.
I finally resolved this problem. As suggested in the other post I linked, a workaround is to append "\u3000", "\u2060", or "\u200b" to the text of the view. This works fine for TextViews, but where my EditText utilizes a hint, the special character must also be appended to the hint (I was only appending to the text). Hope this helps someone else.
Related
I am trying to create a RadioButton in android. My requirement is that the label should be always left aligned and icon should be right aligned(evenly distributed, as first item in attached screenshot). I was able to achieve it. But this is not working when the label has no character and only digits between 0 to 9.
I also tried adding space, but no luck.
Can someone please help?
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listRadioItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:ellipsize="end"
android:layoutDirection="rtl"
android:maxLines="1"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:text="123"
android:layout_gravity="start"
android:textAlignment="textStart" />
I think the easiest solution, if you know it always needs to be left-aligned, is to use
android:layoutDirection="rtl"
android:gravity="center_vertical|left"
Otherwise it might be worth looking into formatting for RTL text because I think the handling of numbers is what's causing that behaviour, where "start" and "end" become flipped (because you don't necessarily want to reverse a number, so it might be treated as LTR - I'm not an expert on any of this though!)
I have a double constraint layout, one is the box which takes all the screen and the second one contains some views (an editTextview in particular). I want that my editText takes all the remaining space on the right, as in the photo below
I've put layout_width = 0dp to achieve this purpose, but it's not working. In fact, the editText seems to be much shorter; I still can write numbers, but they all remain in that portion of space (it shows the last 6 numbers in that part of the editText).
Moreover, when I stop typing and the keyboard disappears, all the numbers, which I've written before, expand on the right, as you can see here:
I've tried to solve the problem using layout_width = 500dp or similar, but the final result is not what I'd like to achieve. I want to be able to write numbers for ALL the line and when I reach it, the first numbers have to disappear from the view and the new written numbers have to appear on the right (I mean, it must show the last 30 characters for example).
Here is the part of the layout with the problem:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/boxEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="#drawable/layout_border"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tabLayout">
<TextView
android:id="#+id/buttonPrefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="+39"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/boxEditText"
app:layout_constraintTop_toTopOf="parent"></TextView>
<View
android:id="#+id/verticalLine"
android:layout_width="1dp"
android:layout_height="25dp"
android:layout_margin="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#android:color/black"
app:layout_constraintBottom_toBottomOf="#+id/buttonPrefix"
app:layout_constraintStart_toEndOf="#+id/buttonPrefix"
app:layout_constraintTop_toTopOf="#+id/buttonPrefix" />
<EditText
android:id="#+id/editTextPhone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/edit_text_border"
android:hint="#string/Telefono"
android:inputType="phone"
android:maxLines="1"
app:layout_constraintBottom_toBottomOf="#+id/verticalLine"
app:layout_constraintStart_toEndOf="#+id/verticalLine"
app:layout_constraintTop_toTopOf="#+id/verticalLine" />
</androidx.constraintlayout.widget.ConstraintLayout>
I'm not sure which pictures show the working and which ones show the not working examples, but i noticed this:
You forgot the end constraint:
app:layout_constraintEnd_toEndOf="parent"
And if the text overlaps your background you can probably add some padding:
android:paddingEnd="16dp"
If i have understood good, you can write
android:gravity="right"
In that way, you will start typing from the right side, and as you keep typing, the first numbers will go to the left. Now, if you want a specific number of characters to show up, you can achieve that by changing the size of the number.
I want the textview to show excess characters entered and push the old ones left as in any standard calculator app where the latest character entered is visible. The maxLength = 14. When characters are typed (once 14 characters are entered as in the image) then it doesn't show them at all. I think I am doing something wrong but can't figure it out what. I have read other answers on stackoverflow for some similar errors and tried the solutions but it didn't work.
Thanks :)
Here's the xml Code for the textview:
`
<TextView
android:id="#+id/full_expression"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_weight="1"
android:alpha="0.85"
android:background="#android:color/transparent"
android:elevation="6dp"
android:fontFamily="sans-serif"
android:gravity="bottom|end"
android:maxLength="14"
android:maxLines="1"
android:paddingEnd="10dp"
android:scrollHorizontally="true"
android:text="0"
android:textColor="#android:color/background_light"
android:textSize="34sp" />
Use "android:gravity" property to align your text inside textview.
I have a TextView which sits on the left side of the screen and is set with gravity="right" and it is set with SingleLine = "true."
If by some chance the text in this view gets too long I want it to simply disappear off the left hand side of the view. I thought the configuration below would do that but what actually happens is the the long string disappears completely, presumably down and outside of the view somewhere.
How can I create a simple text view that contains a single line of text and keeps its layout even when something unexpected happens? ... or even something predictable.
<TextView
android:id="#+id/tempF"
android:text="#string/tempF"
android:layout_width="146dp"
android:layout_height="wrap_content"
android:textColor="#cccccc"
android:textStyle="bold"
android:textSize="92dp"
android:fontFamily="serif"
android:gravity="right"
android:layout_marginTop="60dp"
android:layout_gravity="top|left"
android:singleLine="true"
/>
This is the purpose of "ellipsize" - truncating a portion of text to indicate additional text.
In you case, you may simply need to add something like:
android:ellipsize="end"
or you might need to go deeper:
Automatically ellipsize a string in Java
Or look at this:
android ellipsize multiline textview
The idea behind extending the class is that you can customize the behavior of the TextView when the text content exceeds the space provided. For example, you can give it the appearance the it "bleeds over" by removing padding, etc. An ellipsis is an indicator that is commonly used to explain "there's more text that you can't see" - this is how it would look:
This is really a really long...
(the 3 periods are the ellipsis - your text goes the opposite direction, but it should still work)
With a custom TextView, you could change the "..." to nothing or anything else you want (even an image, which I've done).
You could also marquee the text:
TextView Marquee not working
Add 2 properties in xml
android:singleLine="true"
android:ellipsize="end"
You should play with ellipsize attribute of the TextView.Check below:
<TextView
android:id="#+id/tempF"
android:text="#string/tempF"
android:layout_width="146dp"
android:layout_height="wrap_content"
android:textColor="#cccccc"
android:textStyle="bold"
android:textSize="92dp"
android:fontFamily="serif"
android:gravity="right"
android:layout_marginTop="60dp"
android:layout_gravity="top|left"
android:singleLine="true"
android:ellipsize="end"
/>
<TextView
android:id="#+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorGray"
android:textSize="#dimen/_18dp"
android:padding="#dimen/_2dp"
android:singleLine="true"
android:ellipsize="end"
android:text="#string/desc" />
Since android:singleLine is deprecated. We can use this line android:maxLines
Can do like this.
android:ellipsize="end"
android:maxLines="1"
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000" />
It works.
I have seen many similar questions to this one but I think this still covers new ground:
1) Hint text disappears when you set gravity
2) android:ellipsize="start" fixes that so you can have centered hints and centered text
3) why does the code below still show centered hint text?
<EditText
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="use this area to provide specific identification information including approximate size, vessel name and registration numbers if available"
android:background="#android:drawable/editbox_background"
android:layout_below="#id/details_title"
/>
is it because of fill_parent instead of wrap_content? i thought maybe it was because this hint is multiline, but i shortened it and it still appeared and was centered. those are the only differences between this and my other EditTexts that needed android:ellipsize="start" to display correctly. is it just a bug?
You need to use android:gravity="top" instead of center in order to have your hint and your text start at the top left of the box.
add this attribute to your EditText
android:ellipsize="start"
It just works
<EditText
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:ellipsize="start"
android:hint="use this area to provide........"
android:background="#android:drawable/editbox_background"
android:layout_below="#id/details_title"
/>