I have an edit text with a background image,
I want to add a drawable in the center of the edit text.
<EditText
android:id="#+id/etReceipt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:clickable="true"
android:drawableStart="#drawable/Draw _Image"
android:background="#drawable/bgImage"/>
is ther a possibility to resize the drawable to fit with the edit text?
is it possible to put it in the center?
Create center.xml in res/drawable folder and add this code
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/bgImage"
android:gravity="center"/>
In your edit text add:
android:background="#drawable/center"
Hope this helps, happy coding!
Related
Hello Guys I need some help in creating Imagebutton. I created custom button on PS and then saved it in PNG format with transparent background. After that i patched my image with 9patch. Now i am using that image as a button in my layout but the image is showing colored background corners. I tried alot of things but its not removing.
Here is my XML
<ImageButton
android:id="#+id/mybutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/registerbutton"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="123dp" />
Keep the background attribute as #null like this :
android:background="#null"
If still you are getting that corner, it might be from the png file that you are using.
This is an example of what i get from #null
Probably the ouput of "9patching" operation added corners. Open the file and check if there are corners or not.
If that won' help, try switching android:src attribute with android:background attribute.
And u can make .png button online using this site
How can I edit text shape like this.
I mean that right rounded corners and exact same shape. As I understood 9 patch doesn't help me with that.
9 patch will be best way in your situation, create 9 patch and set it as background of your EditText.
Here i am giving you sample image, you can try with it.
editText.setBackground(R.drawable.edt_bg);
This ninepatches will help you. just apply this ninepatch images as backgroud of the editText
You have to create background image for your EditText. For the other layout, you have to create layout which will look like this. Its not the exact xml but showing you the idea.
<RelativeLayout layout_width="match_parent" layout_height="50dp">
<EditText layout_width="wrap_content" layout_height="wrap_content"
android:background="#drawable/editTextBackground" layout_alignParentLeft="true" layout_marginLeft="10dp">
<ImageView layout_width="wrap_content" layout_height="wrap_content"
centerVertical="true" marginLeft="15dp"
android:background="#drawable/smily" />
<ImageView layout_width="wrap_content" layout_height="wrap_content"
centerVertical="true"
alignRight="#id/editTExt"
android:background="#drawable/camera" />
<ImageView layout_width="wrap_content" layout_height="wrap_content"
centerVertical="true" marginLeft="15dp"
alignParentRight="true"
android:background="#drawable/mic" />
</RelativeLayout>
Hope this gives you the idea.
I am trying to customize the look of an EditText but I am failing to do so... I would like to have the textfield in rounded borders with a graphic icon to the left (so the icon would be inside the borders too, next to the edittext). Could somebody please explain me how I could achieve this? Do I need to draw the border as a shape or is there some property for this? Thanks a lot!
Try like this
<EditText
android:id="#+id/rLastName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/editbox"
android:hint="#string/lname"
android:padding="5dip"
android:singleLine="true"
android:textColor="#999999"
android:textSize="14dip"
android:drawableLeft="#drawable/ic_launcher" />
Drawable left the icon will be set in left side
You can try this link for rounded corners link
How to create EditText with rounded corners?
And
http://alinberce.wordpress.com/2012/02/20/android-edittext-with-custom-font-and-clear-button/
I am having one contact form in which I would like to add some icons to my edit text for a better look. I want to create EditText something like below.
I have EditText like below. And I got the result something like. I want the image to be absolutely on the left side as it is in the above image. I know that internally EditText is using Nine Patch image and i think that is why the result is some what different. Can anyone know how to resolve this?
<EditText
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="51dip"
android:hint="#string/name"
android:inputType="text"
android:drawableLeft="#drawable/name_icon_edittext" />
Instead of using android:drawableLeft="#drawable/name_icon_edittext", create separateImageView for the name_icon.
This way you have more control on placing it on the layout
Note: I am assuming your layout is RelativeLayout
if you want to add some space between you text and image then use'drawablePadding' property in xml
android:drawablePadding="10dp"
here is complete example how to use in edittext in xml file
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_left"
android:drawablePadding="10dp" />
You can use android:drawablePadding="10dp" property in the xml file.
There's no need to create separate imagview for the icon.
A bit old, but for future reference maybe:
I would do a 9-patch image myself with the appearance you want, keeping the proportions and all but the icon, so you can add it yourself (and reuse the background) with drawableLeft property of EditText. That way only the middle part of the image will be stretched but the rest will stay the same.
can anybody tell how to display background image in a TextView in android?
If you are working with xmls you can add it as Praveen Chandrasekaran said doing:
android:background="#drawable/myResouce"
Before that you have to put your image file inside the res/drawable folder.
You can also change it from the code doing:
mTextView.setBackgroundResource(R.drawable.myResouce);
add a android:background="#drawable/imagefile" attribute on your TextView tag. Before that you have to put your image file inside the res/drawable folder.
android:background="#drawable/mark"
Also review.... your background image should be a 9.png and add some paddings for your content
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
android:layout_height="400dp" android:background="#drawable/mark"
android:paddingTop="5dp" android:paddingBottom="5dp" android:paddingLeft=