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

- 5,938
- 11
- 38
- 68
-
1@TimCastelijns please read the question carefully. its completely different question – Shivanshu Verma Nov 02 '15 at 10:35
-
1@ShivanshuVerma how do you figure? – Tim Nov 02 '15 at 10:37
-
1author needs an EditText on which the right side field is completed by a static text which can't changed by user. m i ryt ? @bearded – Shivanshu Verma Nov 02 '15 at 10:46
-
yes. thats what I wanted – Nabeel K Nov 02 '15 at 10:49
-
try this : http://stackoverflow.com/questions/22562959/how-to-set-the-cursor-to-the-right-edittext – KishuDroid Nov 02 '15 at 11:04
2 Answers
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 anEditText
inside anotherLinearLayout
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 is normal method right ? Apart from the above solution is there a way I could achieve this ? – Nabeel K Nov 02 '15 at 10:55
-
@beardedbeast I've never used it, but isn't `TextInputLayout` interchangeable with `EditText`? – PPartisan Nov 02 '15 at 10:55
-
@beardedbeast You could also, possibly, achieve it with `TextWatcher`, but given that you want one element off to the right and another to the left, this is a more straightforward and robust approach, as near as I can tell. – PPartisan Nov 02 '15 at 10:56
-
-
@beardedbeast Sure, so you should be able to just apply anything said above for `EditText` to your `TextInputLayout` wrapper. – PPartisan Nov 02 '15 at 13:57
-
-
@beardedbeast Just because it's inside a `LinearLayout`? This is a common situation, so I'm surprised. Under what conditions does the label animate correctly? You could swap the `LinearLayout` on that row for a `RelativeLayout`, for instance. – PPartisan Nov 02 '15 at 14:13
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93998/discussion-between-ppartisan-and-bearded-beast). – PPartisan Nov 02 '15 at 14:57
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

- 1
- 1

- 5,411
- 4
- 30
- 47