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"
/>
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 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.
Is there any way to center the inputted text in an EditText field? More specifically, instead of the cursor starting at the left of the box, it should start in the center and move outward towards the left as it is populated with inputs.
you should use
textView.setGravity(Gravity.CENTER_HORIZONTAL);
Try android:gravity="center_horizontal" in the widget definition in your layout file. This will not strictly "move outward towards the left" -- it should move outward in both directions evenly. If you truly mean you want the text to only be on the left side of the EditText, I doubt that will be possible.
Simpler Solution to align text in EditText is to add android:gravity="center" in layout xml. There is no need to add Java code.
Tested Sample Code-
<EditText
android:id="#+id/FieldName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:inputType="numberDecimal"
android:gravity="center" />
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.
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