Text that doesn't fit into EditText - scroll it to the left - android

If I set text to my EditText and the text is bigger, the default behaviour is that the text is scrolled to right. Can I scroll it to left?
Example with EditText 8 characters long and text "Sample text":
Normal behaviour: [ple text]
What I want: [Sample t]

Set the cursor/caret location to first character of the EditText. You need to use setSelection.
Selection.setSelection(editText.getText(), 0);

Related

Get number of visible characters in textview when ellipsize was applied

I want to get the number of characters which are visible in TextView when we have applied android:ellipsize in TextView. Suppose i have "This is dummy top stories title with multiline, This is dummy top stories title with multiline." text and i have set "android:ellipsize="end" android:maxLines="2"" these properties in my Textview , so it will cut down some text and show the 3 dots. Now i want the nuumber of characters which are visible.
In case of singleLine TextView:
stringLength - textView.length()
would give how much text is not shown or ellipsized away in device.
Same way in case of multiline TextView you can use:
Layout textViewLayout = textview.getLayout();
textViewLayout.getEllipsisCount(textViewLayout.getLineCount()-1)
As per Documentation at developer.android.com
getEllipsisCount(int line)
Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.
Note: getEllipsisCount must be used after textview is visible/drawn.

Underline text inside Editbox

As I enter text in editText it should automatically underline the text I entered. I need like as I continue to enter text in editText it draw like in background.
Can someone help me.
Use view with 1 dp of height and custom width with green background , inside framelayout over your editText, and handle custom_width same as you are handling image_width.
For underline effect in EditText you need to add this
//initialize edittext before
editText.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);

How to set bulletspan to a string in edittext at a leading margin?

I have a edittext and some buttons like bold italics underline bullets. Now when i select some text and press any button then using spannable string i am applying that particular span to that portion of the edittext like bold italics underline etc.
I am trying to put Bulletspan in edittext. Here is the code i use to put bullet span:-
s.setSpan(new BulletSpan(), text.getSelectionStart(), text.getSelectionEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
where text is my reference to the Edittext.
Now the issue is that I want that my bulleted text should come at some leading margin space or indentation from start like it comes in any text editor like MS Word.
Just tell BulletSpan how much leading space you want. This example would give you 16dp leading space on the first and subsequent lines (like in the text editors you mentioned).
new BulletSpan(16);

how to set Edit Textbox cursor start to some default position?

im using a edittext box drawable where the border is little graphical like it has two line border.the thing is if i enter the text its overlapping with the edge of the box.how can i create a space/ gap in the beginning,so that i can enter the text after 1/2 spaces gap from the left end.
Thanks
EditText editText = (EditText) findViewById(R.id.textId);
editText.setText("EditText component");
editText.setSelection(3);
try this code to set cursor to position 3.
If you just want to add space at strting try adding paddingLeft attribute in your code.
Thanks.

android EditText and textformatting

in my custom listview that Contain an image and EditText ,and in EditText i can comment the photo ,i can give text comment max length of 50 ,when i lost the focus in EditText i want to rearrange the text in EditText in following format
EG: suppose comment contain 40 char and user can at a time directly view only 20 char,then if i lost the focus text should be rearranged that at the end there should be 3 dot
Original Comment i wirte:eg-> eeeeeeeeeeeeeeeeeeeeeeeeeee after i lost focus it should shown as-> eeeeeeeee...
it's importent that the nothing happens to original text because these text i want to send to server, and i directly take these values,and if am replace the text by new this type of text this will create problem, also when i gain focus i need to see full text also.
i have used this android:ellipsize="end"
You have to set a specific value for android:ems on your EditText if you want to use the ellipsize function as it will only truncate strings longer than the EditTexts width. With ems or maxEms you can specify how many ems wide your EditText should be. Also don't forget to set android:singleLine to true.

Categories

Resources