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);
Related
I have an EditText set to gravity Right, so that the text starts from the right if the language is Arabic.
Note: My application supports RTL, and I am not setting the TextDirection for my EditText as that will have the same problem. Gravity set to Right does the job perfectly. I have an issue only if I set the InputType to Number or Phone.
If the InputType is set to number/phone there are double cursor at the beginning and end of the text and it is a bit confusing.
To demonstrate this, I have two EditText with InputType Text and Number, Gravity set to Right for both. My application supports RTL and My phone is now set to Arabic language
Manifest
android:supportsRtl="true"
XML
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="text"
android:inputType="text"
android:lines="1"
android:maxLines="1"
android:gravity="right"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/phone"
android:inputType="number"
android:lines="1"
android:maxLines="1"
android:gravity="right"
/>
Here is a screen shot of the behaviour for the second EditText with InputType Number.
Any pointers on how to get rid of the double cursor? or any alternative.
Thanks
R
Use properties layout_direction as 'ltr' and gravity 'right'.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/phone"
android:inputType="number"
android:lines="1"
android:maxLines="1"
android:gravity="right" />
This solved my problem.
The Edit text doesn't know if the next char you will press is a number or a letter so in case of a letter it places the far left one while the far right one for a number(Most likely you know that just making sure).
So it will disappear if you switch to English.
I think this is fundamental in the edit text:
Solutions:
1- You can create your own edit text from scratch(From View).(May take month with all the problems that may arise).
2- Find a way to override the edit text to remove the split.
3- Find a git where someone had solved that problem(which I doubt).
This doesn't seem like a problem as a programmer or a user. A designer maybe will be a bit annoyed but ignoring it is the fastest way.
Sorry if this wasn't usefull.
ViewCompat.setLayoutDirection(findViewById(R.id.myedittext), ViewCompat.LAYOUT_DIRECTION_LTR);
it worked for me.
wrap your edittext in linearlayout with horizontal oriation and layoutDirection ltr
try to change android:inputType="number" into phone..
for example :
<com.test.utils.custom.CustomTelephone
android:id="#+id/custom_telephone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:inputType="phone"
android:text="#string/telephone_number_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/iv_logo" />
that worked for me ..
if not work try to add layoutDirection:Rtl in edit Text as attribute ..
Happy coding .. !
I am using a edittext with multiline property.when i type any word there is no underline but as i used space or enter key all the text cover by underline .how it can be remove . I dont want to see underline .so please give me any solution..
my xml file is......
<EditText
android:layout_centerInParent="true"
android:id="#+id/etext"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:visibility="invisible"
android:textSize="20dp"
android:background="#null"/>
I suppose you mean underlines that come with auto-suggestions.
If you don't want them, try this
android:inputType="textNoSuggestions"
in your EditText xml.
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.
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"
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.