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.
Related
I want to use a list separator in my .xml file, but everytime i do that, the text style changes, it becomes bigger and bolder.
Below are links of the screenshots. The picture on the left is what shows up from my code, and on the right is what i really want.
Picture for output
I only want to know how to stop the text from getting bigger and bolder, and at the same time how to put a horizontal line below the <TextView>.
Below is the link for the code
Code
Building from #John Kalimeris' answer, i have a better way, in which no foriegn resource will be needed. This should work for you.
<TextView
android:layout_width="match_parent"
android:layout_height="5dp"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_marginBottom="3dp"/>
for the horizontal line you can use this code:
<TextView
android:id="#+id/tevi_divide"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_margin="3dp"
android:background="#color/detail_line_divider"
android:text="#string/str_empty" />
you put this below your textview. You change the values of height and margin according to your needs.
I need to create a button with the background and place it on the picture. I tried to create LinearLayout Horizontal bet on it, and put the background image and button. but it looks not nice. Tell me how to do this?
No layout is needed here, any TextViews can have drawableLeft attribute. Use appropriate XML attributes to set picture, padding, gravity of the text, etc.
Use button's xml attributes to set a drawable according to your need, and in your case it is drawableLeft. See the example below to make a think like your purpose :
<Button
android:id="#+id/backButton"
android:drawableLeft="#drawable/back_btn"
android:background="#android:color/transparent"
android:text="#string/home_screen_sell_new_card_back_button_text"
android:textColor="#026281"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
And for the little enhancements, put paddings and other stuff.
I have two EditText views on a layout containing a date and a time. On being clicked these open up my custom DatePickerFragment and a TimePickerFragments. I would like to style the EditTexts with a picker drop corner as the following image shows.
however I have not been able to do this, my text fields look like this:
The pickers all work and are hooked up and return values to the EditTexts, I just want to do the styling correctly. I am happy to change the class of the containers from EditText if they should be something else to get the desired behaviour. I think this should be possible as the first image comes from Google's own design documentation. Looking through the EditText and TextView class documentation and xml attibute documentation. Is there a way to do this?
I am using Xamarin to compile this down but that should make no difference to the answer.
set the Style attribute to the following:
<EditText
style="?android:attr/spinnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
use following image as background of your edittext
make it 9 patch with whatever colour you want.
find an original image and Create a nine patch image like below..
Note : Black Lines are patches
And then add image to background of EditText like below..
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/box_edittext"
android:padding="10dp" />
OR
You can use this simple way...
Define style="?android:attr/spinnerStyle" to EditText..
<EditText
style="?android:attr/spinnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
After some pretty thorough googling I still cannot figure out what the the little graphic that's displayed under the text in and EditText View is called. I would also like to remove it either using XML or programmatically. The little graphic is the thing under the cursor in this image: http://1.bp.blogspot.com/-UAuOq0h4Vok/T8reinvaWPI/AAAAAAAABPc/N4yibXd3kZg/s1600/android%2Bedittext%2Btext%2Bchange%2Blistener%2Bexample.jpg . Sorry if this is a dumb question, but without the name of this little graphic feature I can't seem to find out anything about it.
It is the background drawable associated with the edittext. You can change it by manually setting the background to something yourself, such as
<EditText
android:background="#android:color/transparent"
...
/>
Try this..
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/hello"
android:background="#00000000"
/>
if you want transparancy just put 80 before the actual hash code.
#80000000
This will change any colour you want to transparent one.. :)
you probably have in your layout
android:minLines="2"
try to remove it
I am developing an android app in version 2.3. I need to create a editTex that has the same effect as the EditText coast "from" image
![two muppets][1]
You can try it like below.
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minLines="5"
android:drawableTop="#drawable/profile_one"
android:ems="10"
android:hint="Tap to enter title"
android:gravity="top|left" >
<requestFocus />
</EditText>
This line android:drawableTop="#drawable/profile_one" will set the image in your edit-text so just replace profile_one this name with your image name.
Like wise you can set image to left, right, and bottom also with following property.
android:drawableBottom="#drawable/profile_one"
android:drawableLeft="#drawable/profile_one"
android:drawableRight="#drawable/profile_one"
Output
You can set image as background to EditText
You can do a nine patch if its only an image back-ground.
So Create a nine patch image that looks like the one you want and apply it as a background to your EditText.
android:background="your image";
To me it appears more like a spinner though.
I am not agree with either of any other answers, but you could use HoloEveryWhere to provide a compatibility and make your EditText looks similar in all the versions.
You can use nine patch image for the background image of edittext.
Are you luking for spinner more specifically custom spinner
Try custom spinner and create edit text as a custom view that It is to be inflate an image.
Refer following link: http://www.androidhive.info/2012/04/android-spinner-dropdown-example/