Android: EditText displayed with black background


Keywords:android 


Question: 

I have a row with two EditTexts and two ImageButtons. In the preview of android studio everything looks fine and the EditTexts have the default style. But if I display it on my tablet the background is black.

How it should look like:
enter image description here

How it looks like on the tablet:
enter image description here

Other EditText-Boxes are displayed correctly. Does anyone know why the these look different and how I can fix it?

Here the XML-Layout of this line:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_centerHorizontal="true"
    >
<EditText
    android:id="@+id/first_input"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    />
<EditText
    android:id="@+id/second_input"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="2.4"
    />
<ImageButton
    android:id="@+id/first_button"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.3"
    android:src=""
    android:background="@drawable/first_button_background"
    android:onClick="onFirstButtonClicked"
    />
<ImageButton
    android:id="@+id/second_button"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.3"
    android:src=""
    android:background="@drawable/second_button_background"
    android:onClick="onSecondButtonClicked"
    />
</LinearLayout>

EDIT: I tried changing the background color to white but then the EditTexts lose their whole style so also the underlining will not be displayed anymore.


3 Answers: 

this's because the editext default background change based on device theme go for an edittext with custom background and in a simple way include android:background="#ffffff" for your editexts

 

The problem might be occurring due to the imageButtons but You can change the background color of the edittext like this:

android:background="#FFFFFF"
 

May be your tab does not support the selected theme, try to change background color of your edittext using:

android:background="#FFFFFF"

if problem does not solve, then you can change background of edittext programmatically like this:

youeEditText.setBackgroundColor(Color.parseColor("#ffffff"));