0

我有一行有兩個EditText和兩個ImageButton。在android studio的預覽中,一切都很好,EditTexts有默認的樣式。但是如果我在平板電腦上顯示它的背景是黑色的。Android:EditText顯示黑色背景

究竟應該如何樣子:
enter image description here

它是如何看起來像在平板電腦上:
enter image description here

其他的EditText盒正確顯示。 有誰知道爲什麼這些看起來不同,我該如何解決它?

下面這一行的XML-佈局:

<?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="@drawable/move" 
    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="@drawable/trash" 
    android:background="@drawable/second_button_background" 
    android:onClick="onSecondButtonClicked" 
    /> 
</LinearLayout> 

編輯: 我試圖改變背景顏色爲白色,但隨後EditTexts失去他們的整體風格也是如此下劃線將不再顯示。

回答

3

這是因爲基於設備主題editext默認背景變化去自定義背景一個EditText和以簡單的方式包括:android:background="#ffffff"您editexts

+0

我想到了使用自定義主題,但我認爲都必須有默認的樣式,以顯示他們的可能性因爲其他EditTexts正確顯示 – 2015-04-02 12:45:33

+0

已嘗試android:background =「#ffffff」?? – 2015-04-02 12:46:58

+0

是的,我做到了。但然後EditTexts失去了他們的風格,像下劃線.. – 2015-04-02 12:49:48

1

問題可能是由於imageButtons正在發生,但你可以改變在EditText上的背景色是這樣的:

android:background="#FFFFFF" 
+0

thx爲您的答案。但是當我將背景顏色更改爲白色時,EditText的整個樣式也會發生變化。所以下劃線也消失了。 – 2015-04-02 12:43:33

+0

@e_card您是否嘗試更改imageButton圖像的顏色? 嘗試,如果它有任何影響,那麼他們是問題的原因 – Umair 2015-04-02 12:46:06

+0

我改變了圖像的顏色爲白色,但它沒有改變任何與EditTexts。我也完全刪除它們,它們仍然保持黑色。 – 2015-04-02 12:54:04

0

可能是你的標籤不支持選定的主題,請嘗試使用改變你的EditText的背景色:

android:background="#FFFFFF" 

如果問題不解決,那麼你可以以編程方式更改的EditText的背景是這樣的:

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