【问题标题】:Android: EditText displayed with black backgroundAndroid:EditText 显示为黑色背景
【发布时间】:2015-04-02 12:32:26
【问题描述】:

我有一排有两个 EditTexts 和两个 ImageButtons。在 android studio 的预览中,一切看起来都很好,并且 EditTexts 具有默认样式。但如果我在平板电脑上显示它,背景是黑色的。

应该是什么样子:

它在平板电脑上的样子:

其他 EditText-Boxes 正确显示。 有谁知道为什么这些看起来不同以及我该如何解决?

这里是这一行的 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 失去了整个样式,因此也不再显示下划线。

【问题讨论】:

    标签: android android-layout android-edittext background-color android-styles


    【解决方案1】:

    这是因为基于设备主题的 editext 默认背景更改适用于具有自定义背景的 edittext,并以简单的方式为您的 editexts 包含 android:background="#ffffff"

    【讨论】:

    • 我考虑过使用自定义主题,但我认为必须有可能以默认样式显示它们,因为其他 EditTexts 显示正确
    • 我认为自定义背景很好,这使得编辑文本在所有设备中看起来都相似:)
    【解决方案2】:

    问题可能是由于 imageButtons 而发生的,但您可以像这样更改编辑文本的背景颜色:

    android:background="#FFFFFF"
    

    【讨论】:

    • 感谢您的回答。但是当我将背景颜色更改为白色时,EditText 的整个样式也会发生变化。所以下划线也消失了。
    • @e_card 您是否尝试更改 imageButton 图像的颜色?试试看,如果它有任何影响,那么它们就是问题的原因
    • 我将图像的颜色更改为白色,但 EditTexts 并没有改变任何内容。我也完全删除了它们,它们仍然是黑色的。
    • @e_card 我刚刚在我的模拟器中尝试了你的代码,它在这里工作正常。可能是因为背景主题吧?
    • 我不这么认为。因为同一片段上的其他 EditText 以白色背景显示
    【解决方案3】:

    可能是您的标签不支持所选主题,请尝试使用以下方法更改编辑文本的背景颜色:

    android:background="#FFFFFF"
    

    如果问题没有解决,那么您可以像这样以编程方式更改edittext的背景:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2017-08-30
      • 2010-12-02
      • 1970-01-01
      相关资源
      最近更新 更多