Jetpack Compose - TextField ellipsis - android

I am trying to create a single line text input in Jetpack Compose.
Since this input should have a fix width of 200.dp and is only one line, longer text is going to be cut off. Sometimes it looks like the cut off text does not even exist because the cut is made between two letters. In order to show the user that there is "more" text already typed I would prefer an ellipsis (e.g. This is a sample inpu...) effect.
I tried to use the default TextField and BasicTextField composables but there seems to be no easy solution.
Is there a way to create this ellipsis effect in Jetpack Compose?

Related

Highlight a word in TextField Compose (mention case)

I want to make some works typed inside BasicTextField highlighted to appear like a mention.
But I don't have any glue to make, especially with this bug that is still not fixed
https://issuetracker.google.com/issues/199768107?pli=1
Any ideas, please ?

Clickable parts in editable text in Jetpack Compose

What is the best approach in Jetpack Compose when I want text to be completely editable but also want some parts of it to be clickable?
I could use TextField. But is there a way to make some parts of it clickable? And furthermore I would also like to style the text by using AnnotatedString.
I could use ClickableText and make it somewhat editable. But I would also like to select some text while editing. This seems to be harder, on the first glance.
Or should I use none of them?

change Color of one word in a preference summary

Does anyone know how to do this? For me, I would try the usual Html or Spannable that everyone recommends on SOF.However,nothing changes - the preference color stays light gray (I am on android 4.2), unless I try coloring the ENTIRE message - then it works. But I just want a single word in the middle of the sentence to be colored - not the whole thing. The rest should be gray (or whatever the default is on my android).
OK, the issue was that I was supposed to wrap the entire text in Html.fromHtml method. Not just the portion with text I was coloring.

Building a custom span that occupies the full width of the container

I need to create a custom Span that renders its content like source code. Here's an example of what I am trying to achieve. Let's say we have the following text, where I have annotated the start and end of the custom span using square brackets:
Some text [some\nmulti line\ntext] some more text
The prefix ("Some text") and suffix ("some more text") should be rendered normally, but the custom span should be rendered like a code block:
some
multi line
text
I have been looking at using ReplacementSpan for this, since i Have previously used that to create various interesting custom spans, but for this case I just can't get it to do what I want.
I somehow need to get my span to render a full block of graphics, occupying the entire width of the container. Is it even possible to do this?
Android processes multiline spans line-by-line.
The only way I've found is to override TextView.onDraw, compose blocks for each block-span and draw them before (of after, if you want) TextView.onDraw.
Here is an example activity
https://github.com/Babay88/AndroidCodeSamplesB/blob/master/blockquotespanexample/src/main/java/ru/babay/blockquotespanexample/MainActivity.java
It uses customized TextView
https://github.com/Babay88/AndroidCodeSamplesB/blob/master/blockquotespan/src/main/java/ru/babay/blockquotespan/TextViewWithBlockBackgrounds.java
And special BlockQuoteSpan.
You should ensure that each block span starts and ends with a \n.

iphone-style text edit on android

I'm trying to make iPhone-style EditText element on android.
The one that will have an additional clear button appear on the right after text input.
Adding a new button is not a problem, but I'm a bit stuck with another thing.
A button occupies some space on the right part of EditText, and now characters display beneath the button. How to change maximum shown length of input for EditText?
I want EditText width to be N pixels, and editable area to be N-M pixels.
EditText.setWidth changes width for whole edit box.
EditText.setEllipsize should be the proper solution, but docs are empty, and as I see it truncates text based on some String value.
Applying a LengthFilter cut's the input length to number of characters.
Thanks in advance.
I suspect that android:drawableRight will save you a lot of pain.
Seems I've found a solution.
EditText.setPadding(l,t,r,b) seems to work fine, applying only for editable area
Try this : http://mytechead.wordpress.com/2012/02/07/create-ios-like-cleartextbutton-in-android/
This is a very old question, but thought I'd add my two cents for kicks. I'd probably use a 9 patch for this and set the content area to stop the text before it hits the button area.
This would require creating a custom view so that you can add a button in the desired position using relative layout so that it can be clicked to clear the edittext.
Alternatively you can use the compound drawables, but you would need to implement something like this
Handling click events on a drawable within an EditText so that you can handle the click events. Keep in mind that I doubt the button states (eg the down state) will work using this method.

Categories

Resources