EditText displays text slightly off? - android

I am using and EditText to display my app's EULA. The EditText is marked singleLine=false and enabled = false.
When I ev.setText='....', the text appears slightly shifted 1 and 1/2 characters to the left plus down 1 and 1/2 lines. That is, the text is not registered/displayed properly to the top left corner. Any ideas?

Why an EditText? Seems like a TextView would be the more proper vehicle to display that.
As for the text position, it sounds like you have padding (or margins, or both) specified in the XML.

The following code works:
myEtLoginEula.setEnabled(false);
myEtLoginEula.setVisibility(View.VISIBLE);
myEtLoginEula.setText(myJS.getString("EULAText").replace("<br>","\n") + "\n");
myEtLoginEula.setScroller(new Scroller(getBaseContext()));
myEtLoginEula.setVerticalScrollBarEnabled(true);
myEtLoginEula.setMovementMethod(new ScrollingMovementMethod());
I was previously setting the text, .setText(myJS...) after the .setMovementMethod. It does not like that. I had originally obtained all this months back from another SO question regarding scrolling. Seems to work now. I will revisit TextViewinstead of EditTextas well. Thanks for your patience as I am newbie to SO responding!

Related

Is it possible to have TextView with maxLines=2 but if the text has one single long word not break it in 2 lines?

I have a TextView and I set text which I receive from Backend.
the text is either from 1 to 3 words.
Maximum the textview can be 2 lines.
I am using setAutoSizeTextTypeUniformWithConfiguration
and text.breakStrategy = LineBreaker.BREAK_STRATEGY_SIMPLE
And I don't have any success.
wondering is it possible if the text is single word I don't want to split it. I would like to have it in single line with small textSize. if the text is 2 words and long I am fine to show it in 2 lines. The problem is it always breaks the word in 2 lines if it is long while I don't want.
The only solution that comes to my mind is before setting the text to a textview, check whether text has spaces in it.
If it has not that that means it's a single word, so set ptogrammatically maxlines to 1, otherwise set maxlines to 2.
EDIT: I missed text size part. I use this library for autoresizing and it worked so far https://github.com/jivimberg/AutoResizeTextView
it's automatically handled in androidx.appcompat.widget.AppCompatEditText and just set android:maxLines="2"
remove all other properties you set

Simple loop text animation android

I have a TextView with a maxWidth that I want to loop its text in an animation, if the text is too long to fit in this width.
I want this animation to be smooth, infinite, and to have a certain margin between the end of the text to the beginning of the text in the next animation phase.
For example, if my text is:
"And I think to myself what a wonderful world"
, and in a normal single-line+ellipsize TextView configuration it will look like:
[Beginning of TextView]And I think to myself wh...[End of TextView]
Then I want the text to start animating from left to right, until the whole text is shown, and then again (after a certain margin to the beginning of the text).
What is the simplest way to do this? I've looked for it but couldn't find anything promising.
You can add
android:scrollHorizontally="true"
android:ellipsize="marquee"
to your TextView
Note: for it to work, you have to select it in your code:
textView.setSelected(true);
Of course if you need something more customizable and elaborate this may not suits you.

Creating multiline Edit view in android with coding

I have created an EditText object dynamically but I haven't been able to create a multi-line EditText. I have tried this:
EditText et1 = new EditText(this);
et1.setHint("Enter Your Address");
et1.setSingleLine(false);
et1.setHorizontalScrollBarEnabled(false);
et1.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
et1.setLines(7);
Thanks.
Include this in your code:
et1.setMaxLines(maxlines);
Or you can set the specific height for the edit text.
If you want the text to wrap to the next line, add TYPE_CLASS_TEXT to the MULTI_LINE flag:
textArea.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
It is the line:
et1.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
that is the problem. Take that out.
setMaxLines doesn't matter much unless you want to set a max number of lines. You should also avoid setting the height to something specific. WRAP_CONTENT works great.
Even changing it to:
et1.setInputType(android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE);
forces it to a single line edit, which seems odd.
This doesn't work either:
et1.setInputType(android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
which is really freakin irritating. Seems like an android bug...
You also might want to set the vertical scroll on and gravity so it can scroll up and down and starts in the top left.
et1.setGravity(Gravity.TOP|Gravity.LEFT);
et1.setVerticalScrollBarEnabled(true);
What worked for me is:
et1.setSingleLine(false);
et1.setHorizontalScrollBarEnabled(false);
et1.setVerticalScrollBarEnabled(true);
et1.setMinLines(minLines);

Settings background for EDITTEXT cutting words in Android

I am having a strange issue, the words are cutting inside EDITTEXT i have set an image as background. Plz help me... for example here ffsds, is being cut, I want it to shift to bit right so that it doesnt get cut.
Increase paddingLeft value of edit text.
...
android:paddingLeft="100dp"
...
in xml layout.
Increasing the left padding is the easy solution. But if this smiley image is always on the left of the edittext, you can set the image by using the attribute android:drawableLeft on the edittext.

Custom Position of Hint in Edit Text box.

I was wondering if there was any way that I could get a hint at the bottom of an Edit Text view -- and then the user to start entering text at the top of the box.
As a bonus question, is there any way I can make the hint NOT disappear once the user starts entering text.
You can set the position of the text using the "gravity" attribute (as noted at http://developer.android.com/reference/android/widget/TextView.html#setGravity(int)). So to put the text at the bottom you would have;
android:gravity="bottom"
And to answer your bonus question; No, you can't display the hint when text is entered into the edit text view. Displaying the hint only when the box is empty is the defined behaviour as noted at http://developer.android.com/reference/android/widget/TextView.html#setHint(int)
(and yes, I know the links are for TextView, but EditText derives all of its' text positioning and hint handling functionality from TextView).
Actually THERE IS a way to prevent hint from hiding, and it's a cool one :-)
It gives you the Floating Label look with smooth animation very easily and it's from android itself. No extra libraries and stuff.
Try this:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Touch me and I'll fly!"/>
</android.support.design.widget.TextInputLayout>
You can change the behaviour using other xml tags like android:gravity="start|center|end" and others.
As a BONUS, you can use error messages with it :-) Here's the link to that question: https://stackoverflow.com/a/30953551/6474744
And sorry I do not have enough reputatuion to post images, so help yourself:
http://i0.wp.com/androidlift.info/wp-content/uploads/2015/09/Screenshot_2015-09-28-17-03-561.png
Enjoy :-)
The problem with using both android:gravity and android:hint is that they are inter-linked with regard to cursor position.When you position the hint using gravity and you start entering text, it is entered in the same position as the your hint which is a problem if you want it to start traditionally on the top-left corner.

Categories

Resources