android EditText 融入背景

android EditText blends into background(android EditText 融入背景)

本文介绍了android EditText 融入背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用使用 Theme.Holo.Light.DarkActionBar 作为父主题.

My app uses Theme.Holo.Light.DarkActionBar as the parent theme.

当我使用我的 Android 3.2 平板电脑模拟器时,几乎看不到 EditText 形状.看起来它正在尝试在白色上绘制白色.在这里看到:

When I use my Android 3.2 tablet emulator, the EditText shape is almost impossible to see. It looks like it is trying to draw white on white. Seen here:

当我在我的 Android 4.0 平板电脑模拟器上使用它时,EditText 形状看起来还不错.您可以看到沿 EditText 底部的深灰色线.如果您查看上图,您将在与浅灰色背景水印相交的同一位置几乎看不到一条白线.

When I use it on my Android 4.0 tablet emulator, the EditText shape looks just fine. You can see the dark grey line along the bottom of the EditText. If you look in the above image, you'll just barely see a white line in the same place as it crosses the light grey background watermark.

这是我在布局中的 EditText:

Here is my EditText in the layout:

<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 绘制的颜色错误?我没有覆盖绘图代码或背景可绘制对象.

Why is my EditText getting drawn the wrong color? I'm not overriding the drawing code or the background drawable.

推荐答案

其他答案实际上并不能解决我的问题,我从未弄清楚是什么真正导致了问题.然而,这就是我解决它的方法:我的解决方法是从 Ice Cream Sandwich 复制 EditText 小部件的 .9.pngs 和样式,然后硬编码到我的 Honeycomb 和 Ice Cream Sandwich 应用程序中.

The other answers weren't actually solutions to my problem and I never figured out what was REALLY causing the issue. However, this is how I solved it: My workaround was to copy the .9.pngs and styling for the EditText widget from Ice Cream Sandwich and hardcoded into my app for Honeycomb and Ice Cream Sandwich.

我创建了一个名为 res/drawable-nodpi/edit_text_holo_light.xml 的文件,其中包含以下内容:

I created a file called res/drawable-nodpi/edit_text_holo_light.xml with the following:

<?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中创建了一个样式来设置:

Then I created a style in my styles.xml to set:

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

然后我从 android sdk 中复制了 .9.png 文件并将它们放入 res/drawable-* 中.文件名列在上面的 xml 中.

Then I copied the .9.png files from the android sdk and put them in res/drawable-*. The filenames are listed in the above xml.

这篇关于android EditText 融入背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:android EditText 融入背景

基础教程推荐