)
I am having a bit of a problem with my app. I am using a multiline edit text.
I want its content to have a bit of a left space (not the edittext, but the text in it), because of a drawable i set as backgroud for the edittext.
Just like padding works for layout alignment, is there anything to align text?
Try:
<EditText
.....
android:paddingLeft="50dp"
.....
/>
If you want to have a padding,
You can simply use android:paddingLeft="20dp"
or android:padding="20dp" for your EditText in your XML.(i don't know exactly what you want, just try).
If you want to align your text,
Try to use Android:Gravity in order to align your text in your EditText.
Here is the code : android:gravity="right" (in order to have right align for your text)
You can find more information about what you can do with this here : Android Gravity
Related
I have a multiline EditText, for editing Arabic text, as you can see Android cuts off some characters because they are rendered right after zero margin (adding spaces is not a solution because it's multi-line and the user changes the text by editing, adding padding and margin is not a fix too):
Did you try to add padding correctly?
You may try this:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
paddingLeft and paddingRight make sures that it leaves 10dp size left and right of your text inside your EditText.
Also you can may add some attributes to this EditText that I think it would be great:
android:gravity="center"
android:textDirection="rtl"
gravity="center" would make the text be centered at the center of the EditText (You may like this approach but it shouldn't be necessary to fix the above problem).
textDirection="rtl" make sures that this language is from right to left so it would be more professional to make it.
You may also try this instead of paddingLeft and paddingRight:
android:paddingStart="10dp"
android:paddingEnd="10dp"
I want to display a textview with a compound drawable which wraps the content - the shape and the text. Here is my code:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text_category_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:drawableStart="#drawable/shape_circle"
android:drawablePadding="10dp"
android:padding="10dp"
android:textSize="16sp" />
drawableLeft works fine, it wraps the shape and and text, no problem. But drawableStart (and so I assume drawableEnd) seems to wrap the text, THEN add the image, and as such trim the text, so it looks like this:
I've tried removing the drawablePadding, padding, layout_marginStart - these don't have an effect on the text still being trimmed.
Is there a non-hacky way to fix this? I don't want to have to set a specific width, and I do want to use drawableStart and not drawableLeft if possible. I've had a look for existing answers, and all I can find so far is that it is a quirk of the RTL nature of drawableStart/End, but I can't see a clean solution.
I want to insert a clickable ImageView/ImageButton at the end of a multiline TextView, similarly to this example:
Text text text text text text text
text text text text text text text
text text text text text text text
text text text text text text text
text text text. | Image |
I was able to implement this using an ImageSpan and ClickableSpan that I added to the TextView, as suggested here and here. This works quite well, however, the ImageSpan doesn't support selector states, so it is impossible to provide the user with a visual feedback when the ImageSpan is focused or pressed (which is quite bad).
Does anybody know perhaps an alternative solution to implement this? Perhaps by using some custom layouts (like a FlowLayout that works with multiline TextViews)?
Thanks!
Just to close this question: I went for the custom span solution as suggested by pskink in https://stackoverflow.com/a/21933957/441370. This worked perfectly fine. Thanks again!
If You dont want click on that Image, Then you can use drawableRight property for EditText..
android:drawableRight="#drawable/icon"
If you want click then use below code.
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter search key" />
<ImageButton
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#drawable/search"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:text="Button"/>
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.
In edittext the text is coming leftmost corner. but i want to display the text after one space . so it should be more readable.
Any one can help me in this problem.which tag in edit text i have to use.
Try providing margins around your EditText Background like this,
<EditText android:id="#+id/tickets_value"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dip"
/>
You can use either the padding or the margin element of the view.
While margin offsets the entire view the padding offsets the content within the view.
http://developer.android.com/reference/android/view/View.html