gpt4 book ai didi

android - 更改 Android EditText 背景颜色

转载 作者:行者123 更新时间:2023-12-02 03:23:47 26 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序。 EditTexts 存在这个问题,因为在某些设备中“背景”是白色的(这就是我想要的方式),但在其他设备上是透明的,并且使应用程序不太专业。这是带有“白色背景”的图像:

enter image description here

在其他设备上,“Yo”和“Casa”的编辑文本是透明的,因此这些单词与 map 混合在一起,非常糟糕。
我尝试更改 android 布局 xml 中的背景颜色。最接近的是我相信@drawable/white,但稍微改变了编辑文本的位置和大小,使它们看起来像是一个,甚至更糟糕。这是一个例子:

enter image description here
有没有一个好的方法来解决这个问题?我在某处读到一个选项是在编辑文本中添加白色背景图像,但似乎很麻烦。

更新
我尝试添加背景图像,但它与使用 android:background 将背景颜色更改为任何颜色相同,编辑文本变得更小或其他。我向图像添加了一个蓝色“分隔符”,这就是结果:

enter image description here

但我希望它们像第一张图片中那样,而不是彼此如此接近。

这将是 edittext 布局 XML 的代码,另一个看起来非常相似。仅通过添加 android:background 标签即可从图 1 变为图 3

解决方案
为了解决这个问题,我所做的是设置背景图像并以 dp 为单位设置其高度,如下所示:

<EditText
android:id="@+id/markerTitle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/buttonModifymarker"
android:ems="10"
android:inputType="textPersonName"
android:text="Título"
android:background="@drawable/editwhite"
>

最佳答案

为什么不尝试以编程方式设置 EditText 的背景?

yourEditText.setBackgroundColor(Color.WHITE);

或者...

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

关于android - 更改 Android EditText 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25834213/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com