Android
Android

Reputation: 3868

Regarding edit text complete border

I am new to android. I was creating one sample page in which I need to give the background of page as white. but then, if not focused my edit text was not visible with white background. How could I add border of desired color to my edit text so that it become visible. Apart from that when ever I was pressing enter in edit text box it was adding a new line to it. I want to remove this also. Can any body help me out in this. Thanks in advance

Upvotes: 5

Views: 22645

Answers (2)

AJcodez
AJcodez

Reputation: 34166

You need to set the background of the EditText to a Drawable resource that does exactly what you want. The best way to do that is with a selector (commonly used for buttons to get the normal, hovered over, and pressed/clicked down looks all in one resource.) http://androidwizard.net/2010/02/custom-button-backgrounds-using-a-selector-xml-layout/

In your selector, choose the images you want to switch between depending on if the EditText is focused on or not. Hiral has a sample image drawn with shapes, but you should figure out exactly what you want it to look like for each state.

As for the new lines, if you want it all on one line go with Hiral, if you want multiple lines but no new lines from enter, see this Prevent enter key on EditText but still show the text as multi-line

Upvotes: 0

Hiral Vadodaria
Hiral Vadodaria

Reputation: 19250

You can set a drawable for your edittext.

edittext_bg.xml:(put this file in your drawable folder)

<?xml version="1.0" encoding="UTF-8" ?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="#ffffff" /> 
  <stroke android:width="3dp" android:color="#000000" />   
  <padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" /> 
</shape>

then set your edittext's background as android:background="@drawable/edittext_bg". But this will remove all default background effect of edittext.You can make a selector for edittext for giving it different background when it is in selected state or normal state.

And you can set android:singleLine="true" in your edittext tag to prevent it to have multiline in edittext.

Upvotes: 30

Related Questions