【问题标题】:change edittext text color in older platform version在旧平台版本中更改 edittext 文本颜色
【发布时间】:2014-03-26 13:00:06
【问题描述】:

我正在为我的应用程序使用深色背景。 edittext 的文本颜色设置为白色。它在最新版本中运行良好。但在旧版本中,由于edittext 本身显示为白色,我无法在edittext 中看到输入的文本。我该如何处理?

【问题讨论】:

  • 检查你的 style.xml 可能是它定义了白色背景来查看。
  • 我想在最新版本中保持不变。只需要在旧版本中更改文本颜色。可以吗?

标签: android android-edittext platform


【解决方案1】:

res/drawable中新建xml文件,将其命名为rounded_edit_text,然后粘贴:

<?xml version="1.0" encoding="utf-8"?>
<shape  xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" android:padding="10dp">
    <solid android:color="#F9966B" />
    <corners
        android:bottomRightRadius="15dp"
        android:bottomLeftRadius="15dp"
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp" />
</shape>

res/layout复制并粘贴以下代码(EditText的代码):

<EditText
    android:id="@+id/txtdoctor"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/rounded_edit_text"
    android:ems="10" >
    <requestFocus />
</EditText>

【讨论】:

    【解决方案2】:

    您可以使用 API 级别 1 中包含的这个东西:

    editText.setTextColor(getResources().getColor(R.id.your_color));
    editText.setBackgroundColor(getResources().getColor(R.id.your_color));
    

    【讨论】:

      【解决方案3】:

      您在 style.xml 中将背景设置为白色。
      在旧版本中,它还将设置为editttext的背景颜色,类似视图的对话框;
      请检查此answer
      这是关于设置 android:windowBackgroundandroid:colorBackground
      希望对你有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-06
        • 2016-03-04
        相关资源
        最近更新 更多