8

我的應用使用Theme.Holo.Light.DarkActionBar作爲父主題。android EditText融入背景

當我使用我的Android 3.2平板模擬器時,EditText形狀幾乎不可見。看起來它試圖在白色上畫白色。在這裏看到:

enter image description here

當我使用它在我的Android 4.0平板模擬器,在EditText上造型看起來就好了。您可以看到EditText底部的深灰色線條。如果你看上面的圖片,你會在穿過淺灰色背景水印的同一個地方几乎看不到一條白線。

enter image description here

這是我在佈局的EditText:

<EditText 
    android:id="@+id/fieldName" 
    style="@style/PlayerDetails.Field" 
    android:capitalize="words" /> 

這裏是風格:

<style name="PlayerDetails.Field"> 
    <item name="android:layout_weight">0.65</item> 
    <item name="android:paddingLeft">10dp</item> 
    <item name="android:layout_width">0dp</item> 
    <item name="android:layout_height">fill_parent</item> 
    <item name="android:layout_marginLeft">10dp</item> 
</style> 

爲什麼我的EditText越來越繪製的顏色不對?我不重寫繪圖代碼或背景繪製。

+0

嗨Kenny Wyland,你找出你的問題。我也面臨同樣的問題。 – 2012-03-31 17:28:05

+0

我從來沒有想出這個問題,但我的解決方法是複製.9。PNG和冰淇淋三明治造型,並硬編碼到我的應用程序蜂窩和冰淇淋三明治。 – 2012-04-01 17:17:59

+0

看到下面的鏈接 http://stackoverflow.com/questions/9224560/how-to-change-the-border-colorun-focused-of-an-edittext?answertab=active#tab-top – DKV 2013-09-11 10:04:38

回答

5

其他答案不是我的問題的實際解決方案,我從來沒有想出什麼是真正導致這個問題。然而,這是我解決它的方法:我的解決方法是從Ice Cream Sandwich複製EditText小部件的.9.png和樣式,並將其硬編碼到蜂窩和冰淇淋三明治的應用程序中。

編輯:

我創建了一個文件名爲res /繪製-nodpi/edit_text_holo_light.xml下列要求:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:state_multiline="true" android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/textfield_multiline_default_holo_light" /> 
    <item android:state_multiline="true" android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_multiline_disabled_holo_light" /> 
    <item android:state_multiline="true" android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_multiline_activated_holo_light" /> 
    <item android:state_multiline="true" android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/textfield_multiline_focused_holo_light" /> 
    <item android:state_multiline="true" android:state_enabled="true" android:drawable="@drawable/textfield_multiline_default_holo_light" /> 
    <item android:state_multiline="true" android:state_focused="true" android:drawable="@drawable/textfield_multiline_disabled_focused_holo_light" /> 
    <item android:state_multiline="true" android:drawable="@drawable/textfield_multiline_disabled_holo_light" /> 

    <item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/textfield_default_holo_light" /> 
    <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_disabled_holo_light" /> 
    <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_activated_holo_light" /> 
    <iten android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/textfield_focused_holo_light" /> 
    <item android:state_enabled="true" android:drawable="@drawable/textfield_default_holo_light" /> 
    <item android:state_focused="true" android:drawable="@drawable/textfield_disabled_focused_holo_light" /> 
    <item android:drawable="@drawable/textfield_disabled_holo_light" /> 
</selector> 

然後我在styles.xml創造了一個風格設置:

<item name="android:background">@drawable/edit_text_holo_light</item> 

然後我從android sdk複製了.9.png文件,並將它們放在res/drawable- *中。文件名在上面的xml中列出。

+0

我遇到了同樣的問題,請給我更多關於如何解決這個問題的細節。 – gath 2012-07-03 05:10:22

+2

我進入android sdk文件夾查找用於繪製標準文本字段的.9.png文件。例如,其中一個名爲textfield_activated_holo_light.9.png。我將所有這些文件複製到我的res/drawable-v11目錄中,以便它們可用於包括v11在內的任何Android版本。然後,我添加了一個drawable-nodpi/edit_text_holo_light.xml,並在其中複製了原始Android樣式的樣式。 (這裏包括太多東西,我會更新我的答案) – 2012-07-03 22:51:00

0

我想出了我的問題。通過在manifest.xml文件中設置應用程序元素android:theme="@android:style/Theme"中的主題。

<application 

android:label="@string/app_name" 

android:icon="@drawable/logo" 

android:vmSafeMode="false" 

android:theme="@android:style/Theme"> 

試試這個。

+2

我使用的是標準的android主題。 Holo,但它在3.0之前不存在,因此我使用Google提供的標準代碼在基於操作系統版本的Theme和Theme.Holo之間切換。問題不在於我沒有使用主題..問題是Honeycomb上的Theme.Holo在所有設備上的行爲不正確。 – 2012-04-03 22:28:57

+0

我有同樣的問題。我在摩托羅拉Xoom平板電腦上測試我的應用程序。我已經設置了Theme.Holo,但沒有任何改變(EditText仍然混合到背景中)。也許我會不得不做一些硬編碼。 – Sandra 2012-04-09 11:11:34

1

你可以有一個操作欄,仍然可以看到該EditText淺灰色的背景水印,如果你使用的主題象下面這樣:

AndroidManifest.xml中

<activity 
    android:name=".ClassName" 
    android:label="ClassName" 
    android:theme="@style/MyTheme" > 

styles.xml

<resources> 
    <style name="MyTheme" parent="android:Theme.Holo.Light"> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 
    </style> 
    <style name="MyActionBar" parent="android:Widget.Holo.ActionBar"> 
    <item name="android:background">@color/black</item> 
    </style> 
</resources> 

這適用於主題「android:Theme.Holo.Light」,但不適用於主題「android:Theme.Holo」。