Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Android EditText background color

I am developing an Android app. There's this issue with the EditTexts, because in some devices the "background" is white (which is the way I want it), but on others is transparent, and makes the app less professional. Here's an image with the "white background":

enter image description here

On other devices the edit texts that say "Yo" and "Casa" are transparent, so the words mix with the map and its pretty awful.
I have tried changing the background color in the android layout xml. The closest one was I believe @drawable/white, but slightly changes the position and size of the edit text, making them look like they're one and its even worst. Here is an example:

enter image description here
Is there a nice way to approach this problem? I read somewhere that an option was to add a white background image to the edit texts, but seemed like a lot of trouble.

UPDATE
I tried adding a background image, but its the same as changing the background color to any color using the android:background, the edit texts get like smaller or something. I added a blue "delimiter" to the image and this is the result:

enter image description here

But I want them like in the first picture, not so close one to another.

This would be the code of the edittext layout XML, the other one looks very similar. Only by adding the android:background tag changes from picture 1, to picture 3

SOLUTION
To solve this what I did was set a background image and set its height in dp as follows:

<EditText
        android:id="@+id/markerTitle"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/buttonModifymarker"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Título"
        android:background="@drawable/editwhite"
         >
like image 985
Victor Avatar asked Sep 14 '14 14:09

Victor


People also ask

How do you edit a text box on Android?

Step 1: Create a new project in Android Studio and name it EditTextExample. Step 2: Now Open res -> layout -> xml (or) activity_main. xml and add following code. In this code we have added multiple edittext and a button with onclick functionality.


1 Answers

Why don't you try setting the background of EditText programmatically?

yourEditText.setBackgroundColor(Color.WHITE);

or...

yourEditText.setBackgroundColor(Color.parseColor("#ffffff"));
like image 109
Gingerade Avatar answered Oct 13 '22 09:10

Gingerade