How to decrease margin and padding of editText programmatically (android) - android

I have editText which by default leaves lots of space. I added backgroud for textView, cause editText backgroud is not possible.
When I execute command: editText.setHeight(50); of no matter what integer it gives me same result:
My text gets cropped. I think somehow I need to reduce editText margins to fit my text here.
Main problem is that there is to much space between rows in first picture.

You can do like this
int reducedValue =5;
editText .setPadding(editText .getPaddingLeft()-reducedValue,
editText .getPaddingTop()-reducedValue,
editText .getPaddingRight()-reducedValue,
editText .getPaddingBottom()-reducedValue);
editText.setCompoundDrawablesWithIntrinsicBounds(editText .getPaddingLeft()-reducedValue,
editText .getPaddingTop()-reducedValue,
editText .getPaddingRight()-reducedValue,
editText .getPaddingBottom()-reducedValue);

Related

Constraint element to the TextInputLayout text (inside the TextInputLayout)

I have a TextInputLayout with only an EditText inside it.
I'm interested in adding a TextView of my own to it, as a potential error text (e.g. "invalid email") and have the following constraints:
1. end of my TextView to end of the TextInputLayout
2. top of my TextView to top of already existing hint, when the latter is on top (preferably with the same text size, but I'm assuming I can achieve that by playing with the sizes a little bit), meaning some text has already been inserted.
Is there any way that this can be achieved?
EditText has a facility of setError(). You need to put some conditions where to set error and where to clear.
No need of extra textview for error message.

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 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.

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

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);

Categories

Resources