如何在Android中将标签和textView组合在一起? [英] How to group together a label and a textView together in Android?

查看:36
本文介绍了如何在Android中将标签和textView组合在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Android 中垂直地将标签(例如StaffID")和 textView 的值(例如S1234567")组合在一起.当用户在 textView 中输入值时,标签始终位于 textView 值的顶部.附件是我想要的 UI 的截图.

I want to group together the label (e.g. "StaffID") and the value of the textView (e.g. "S1234567") together, vertically, in Android. The label stays on top the textView value throughout while the user is typing in the value in the textView. Attached is the screenshot of how I want the UI to look like.

点击此处查看界面截图

推荐答案

使用 TextInputLayout 和所需的 android:hint 属性包裹编辑文本.

Wrap the edit text with TextInputLayout with the desired android:hint attribute.

<com.google.android.material.textfield.TextInputLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
    
     <com.google.android.material.textfield.TextInputEditText
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="StaffId"/>

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

查看官方文档了解更多信息和特点

check the official docs for more info and features

这篇关于如何在Android中将标签和textView组合在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆