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

如何将com.google.android.material.textfield.TextInputEditText替换为TextView?

实现带边框和浮动标签的TextView

要把原来的输入框样式改成TextView版本,直接用TextInputLayout包裹TextView就能实现类似效果,调整以下属性即可匹配需求:

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="32dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="32dp"
    app:boxStrokeColor="@color/blue"
    android:hint="Full Name">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="@font/quicksand_bold"
        android:text="John Doe" <!-- 替换为你要显示的实际文本 -->
        android:textColor="@color/blue"
        android:paddingVertical="16dp" <!-- 让内容和边框的间距与原EditText对齐 -->
        android:paddingHorizontal="4dp" />

</com.google.android.material.textfield.TextInputLayout>

关键调整说明:

  • 把原EditText的hint移到TextInputLayout的android:hint属性上,标签会自动浮在边框上方,和输入框填完内容后的效果一致
  • 给TextView添加垂直内边距,保证视觉上和原输入框的内容间距统一
  • 如果希望标签默认固定在上方、不需要动画,可以额外添加app:hintAnimationEnabled="false"属性

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 13:04:52