在某个设备上黑色的EditText黑色

时间:2015-01-22 09:44:09

标签: android xsd android-edittext

我有一个非常奇怪的问题,在我测试应用程序的每个设备上,edittext的行为与您期望的一样,文本突出显示,并且在白色背景上为黑色。

特别是在联想瑜伽平板电脑上,当编辑文本聚焦时,文本将变为黑色并与背景融为一体。

enter image description here

这个布局是:

 <RelativeLayout
                android:id="@+id/ip_layout"
                android:layout_below="@id/display_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dip"
                android:layout_marginLeft="10dip"
                android:layout_marginRight="10dip">
                <LinearLayout
                    android:layout_marginBottom="10dip"
                    android:background="#8A8A8A"
                    android:layout_height="wrap_content"
                    android:paddingLeft="5dp"
                    android:paddingRight="5dp"
                    android:paddingTop="1dp"
                    android:layout_width="match_parent" />
                <EditText
                    android:layout_marginTop="10dip"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="false"
                    android:hint="@string/Hostname"
                    android:singleLine="true"
                    android:imeOptions="actionNext"
                    android:background="@android:color/transparent"
                    android:id="@+id/host_address"
                    android:maxLength="50" />
            </RelativeLayout>

2 个答案:

答案 0 :(得分:1)

您必须创建自己的九个补丁图像,并将其用作EditText的背景,否则编辑文本将使用设备和版本的android。

如果你想为edittext背景创建更多效果,如按下,聚焦和默认状态,那么你需要为edittext的背景图像创建一个选择器:

<?xml version="1.0" encoding="utf-8"?>
<selector 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:state_pressed="true"
        android:drawable="@android:drawable/Epressed"/> 
    <item 
        android:state_focused="true"
        android:drawable="@drawable/Efocused"/>
    <item 
        android:drawable="@android:drawable/Edefault"/>
</selector>

答案 1 :(得分:1)

如果在特定设备上出现问题,可能是由于设备自定义主题。最近的Android设备需要支持Holo主题,您可以使用以下命令在清单中明确询问该主题:

<style name="AppTheme" parent="android:Theme.Holo" />
相关问题