Edittext - Move Start of Text - android

In this edittext I use, text written on it starts too left. How can I make it so it is moved more to the right? And... what is that black cursor at the left? It disappears for some reason if I set gravity to the center. Thanks a lot
<EditText
android:layout_width="300dp"
android:layout_height="40dp"
android:id="#+id/editText"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:hint="#string/hint_1"
android:background="#drawable/shape" />

You can set position bye
editText1.setSelection(position)
May this will work
Another
etmsg.setText("test");
int position = etmsg.length();
Editable etext = etmsg.getText();
Selection.setSelection(etext, position);
Where etmsg is your Edittext

You can set position by:
editText.setSelection(position)
so, to go to the beginning , use editText.setSelection(0);

If you want to move right then you can use
android:paddingLeft="10dp"

Use padding
android:paddingLeft = "5dp"

Related

Android Button widget hyphenation

I have a problem with my project. I use android.widget.Button. When word can not fit in one line in the Button then it cut it like this: Somelon>gword (where '>' is new line). How to fix it? And how to create inner padding for the text because the long word touches the button's borders?
You can try below code. Where paddingRight and paddingLeft keep padding of 25dp in right and left. If you want to text on in one line.Then
you can use android:singleLine="true"
<Button
android:id="#+id/she_was_good"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="25dp"
android:paddingLeft="25dp"
android:ellipsize=”marquee”
android:text="#string/im_sorry_lol_str" />
Read this post
Try using the property android:singleLine="true" and android:padding="10dp" to your button widget.

How to set the cursor to the right (EditText)?

How to set the cursor to the right with right align and hint text?
Is it possible?
I have a AutoCompleteTextView and a EditText with Text right align and an hint text.
Now if one of them is focused the curser is before the hint and not at the end of the line.
So it looks like now it's bad...
I've also tried to set the cursor position, but it didn't help of course.
<AutoCompleteTextView
android:id="#+id/input_snm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/input_ipAdresse"
android:ems="10"
android:gravity="right"
android:hint="#string/input_snm"
android:imeActionLabel="#string/Button_berechnen"
android:imeOptions="actionDone|flagNoExtractUi"
android:inputType="phone"
android:paddingRight="#dimen/padding_small"
android:textSize="#dimen/fontsize_medium" />
Image: EditText
Ok, I think it's an System error, isn't it?
You can use like this:
if (your_edittext.getText().length() > 0 ) {
your_edittext.setSelection(your_edittext.getText().length());
}
Can you add this line to your EditText xml
android:gravity="right"
android:ellipsize="end"
android:paddingLeft="10dp"//you set this as you need
But when any Text writing you should set the paddingleft to zero
you should use this on addTextChangedListener
Set the android:Theme.Light style on the activity (theme) and android:gravity="right".
This works for me.
textview.setTextDirection(View.TEXT_DIRECTION_RTL);

Set starting point of Edittext

I've got an EditText with my own style. Basically it's a border for the EditText. The problem is that the text starts over this border so it's not very nice. Is there a way of set the starting point of the text in an EditText?
give padding at starting side in layout like this
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
...
android:paddingLeft="10dp"
/>

Padding for hint text inside EditText

I want to be able to add padding to the text that is displayed inside the EditText, using
android:hint="some text"
If I only add padding for the EditText regularly, it adds the padding for the whole view. And i want it for the text that gives a hint for the user, what needs to be entered. If someone knows how to do this, please give me a feedback.
You may find your solution in this answer:
EditText set text start 10dp from left border
It helped me to achieve the padding for hint in username field:
<EditText
android:id="#+id/txtUsername"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:background="#drawable/bkg_login_txt_usuario"
android:hint="#string/hint_username"
android:paddingLeft="10dp"
android:singleLine="true" >
<requestFocus />
</EditText>
I hope this helps.
You can use android:drawablePadding which denotes the padding between the drawable and the hint texts.
Use the TextChangedListener and a TextWatcher to monitor the text inside the EditText. Use the TextWatcher check to see if the EditText is empty and set the padding, otherwise remove the padding.

Android EditText problems

i have created an EditText like this
<RelativeLayout>
<TableLayout>
<TableRow>
<EditText android:id="#+id/myid"
android:hint="This is my hint"
android:textColorHint = "#color/white"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:textSize = "20sp"
android:textColor = "#color/white"
android:textStyle = "bold"
android:background ="#drawable/mybackgroundimage"
android:fitsSystemWindows = "true"
android:includeFontPadding = "true"
android:singleLine="true"
android:cursorVisible = "false"
>
</EditText>
</TableRow>
</TableLayout>
Its in a table layout. i have 2 problems
As soon as i remove android:gravity="center" hints shows but i need to show text from centre and show hints in edit text as well(Is it a bug in android sdk?).
i like to wrap text up-to a certain size if texts grows larger than textview bounds.Right now it goes beyond the view and doest not shows the entered digits after its ending but digits keeps on getting added in edit text.
Please if anyone have any idea how to do this.
Thanks
To show all the text in the EditText just add:
android:scrollHorizontally="true"
As soon as i remove android:gravity="center" hints shows but i need to
show text from centre and show hints in edit text as well(Is it a bug
in android sdk?).
I don't understand what you mean at the fist point. Can you explain it to me?
(if i understand the question)android:gravity="center" allways refear to the "son" of the view. the "son" of the EditText is the text. If you want to put the EditText in the center and the text in the center you should put other gravity=center in the tablerow.
You should change the size of the text programatically:
if (myid.getText().toString().lengh()> XX )
myid.setTextSize("xxdip")
Or something like this

Categories

Resources