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.
Related
I want to display text at the end of EditText as shown in the image above for URLName.How could I acheive this ?The text cannot be edited.I am using this editText inside TextInputLayout from the design library. thanks in advance
Create a LinearLayout. An example of a row inside this layout would be a title (i.e. URL name) or a text entry field.
Set the background of the LinearLayout for the current row to a custom drawable to create a thin red line. Follow the answers on this post for ideas.
For the URL entry field mentioned in your question, create a TextView and an EditText inside another LinearLayout inside the current row.
The TextView will contain ".sitename.com". Set it to wrap_content and give it a weight of 0. For your EditText, set its width to 0dp and its weight to 1. It should now fill all remaining space. Set the background to #null for both.
This worked for me :
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_alignParentLeft="true"
android:id="#+id/youeeditid"
android:layout_gravity="center"
/>
<TextView
android:id="#+id/text_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="HintText"
android:textSize="18sp"
android:layout_marginRight="10dp"
android:textColor="#808080"
/>
</RelativeLayout>
It's little bit tricky but it's works for me.
BUT
If you want to set only EditText then you can do below :
1) Set Gravity of EditText to "Right" and Ellipsize to "End" .
2) Now In onCreate() method write onclicklistener of EditText and set
Gravity as "Left".
3) Or you can also set programatically on OnKeyListener , where check
if lenght of edittext is equal to Zero set EditText's gravity as
Left.
Reference : Setting cursor to the right on an EditText with HINT Gravity to center
I have this EditText
<EditText
android:layout_width="match_parent"
android:layout_height="72dp"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textImeMultiLine"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
When the box is filled up with user inputted text, it scrolls to the right to make room for more text, I do not like this behavior, and would prefer it if the EditText box expanded upwards when it needs more room? Is there a way to do this? Thanks.
Yes, this actually involves two things:
Making the EditText accept multi-line input.
Having its height grow as more text lines are added.
Therefore, to achieve this, you need to set up:
android:inputType="textMultiLine"
android:layout_height="wrap_content"
(Be mindful of the difference between textMultiLine and textImeMultiLine).
The full XML snippet would be:
<EditText
android:layout_width="match_parent"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
Use both flags: textMultiLine will wrap your input, and textImeMultiLine will provide a break-line key in your keyboard.
<EditText
...
android:layout_height="wrap_content"
android:inputType="textImeMultiLine|textMultiLine"
... />
In my case I have multiline text, but it showed one line and a keyboard:
Though I have already set android:inputType="textCapSentences|textAutoCorrect|textMultiLine", it didn't help. Then I understood that when the keyboard appears in DialogFragment, it collapses the EditText. See DialogFragment and force to show keyboard to show keyboard when DialogFragment shows.
Then I added a short delay (100-300 ms) before showing the keyboard. Now I have:
In AndroidManifest I set android:windowSoftInputMode="adjustResize" for current activity.
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);
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"
/>
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