You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android登录框设置可编辑文本:替换android:hint为android:text无显示

解决EditText替换hint为text后文本不显示的问题

你的EditText只设置了android:textColorHint="@color/white",但没指定android:textColor属性,导致输入的文本颜色和背景(或父布局背景)一致,所以肉眼看不见。另外要确保android:text设置的内容不是空值或空白字符串。

解决步骤:

  1. 给EditText添加android:textColor属性,选一个和背景对比明显的颜色(比如@color/black,根据你的UI需求调整)
  2. 确保android:text属性设置了有效内容(直接写字符串或者引用字符串资源)

修改后的代码示例:

<!-- 用户名输入框 -->
<EditText 
    android:textColor="@color/black" <!-- 添加文本颜色设置 -->
    android:textColorHint="@color/white" 
    android:id="@id/tv_vpn_username" 
    android:background="@drawable/selector_verify_password_fields" 
    android:focusable="true" 
    android:nextFocusDown="@id/tv_vpn_password" 
    android:layout_width="fill_parent" 
    android:layout_height="40.0dip" 
    android:layout_marginBottom="10.0dip" 
    android:text="默认用户名" <!-- 替换hint为具体文本或字符串资源 -->
    android:layout_below="@id/et_description" 
    android:fontFamily="@string/font_family_regular" 
    android:textDirection="locale" 
    android:paddingStart="10.0dip" 
    android:layout_marginStart="30.0dip" 
    android:layout_marginEnd="30.0dip" />

<!-- 密码输入框 -->
<EditText 
    android:textColor="@color/black" <!-- 添加文本颜色设置 -->
    android:textColorHint="@color/white" 
    android:id="@id/tv_vpn_password" 
    android:background="@drawable/selector_verify_password_fields" 
    android:focusable="true" 
    android:nextFocusUp="@id/tv_vpn_username" 
    android:nextFocusDown="@id/bt_save_and_connect" 
    android:layout_width="fill_parent" 
    android:layout_height="40.0dip" 
    android:layout_marginTop="10.0dip" 
    android:layout_marginBottom="10.0dip" 
    android:text="默认密码" <!-- 替换hint为具体文本或字符串资源 -->
    android:layout_below="@id/tv_vpn_username" 
    android:fontFamily="@string/font_family_regular" 
    android:textDirection="locale" 
    android:paddingStart="10.0dip" 
    android:layout_marginStart="30.0dip" 
    android:layout_marginEnd="30.0dip" 
    android:inputType="textPassword" /> <!-- 密码框建议添加密码输入类型 -->

额外排查点:

  • 检查@drawable/selector_verify_password_fields的背景颜色,确保文本颜色和背景有足够对比度
  • 如果需要动态设置文本,在代码中调用tv_vpn_username.setText("你的内容")即可
  • 确认EditText没有被其他布局元素遮挡(从当前布局来看,这个概率很低)

内容的提问来源于stack exchange,提问作者DanW

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 13:20:15