简体   繁体   English

如何在 Android Studio 中执行浮动提示/文本?

[英]How do I do a floating hint/text in Android Studio?

I have a box to type in the user's username, and when the area is selected, I want the "username" text to slide up so it is still visible when typing the username. I have a box to type in the user's username, and when the area is selected, I want the "username" text to slide up so it is still visible when typing the username. See code for more information.有关更多信息,请参见代码。

 <ImageView
        android:id="@+id/imageView8"
        android:layout_width="332dp"
        android:layout_height="45dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="30dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView7"
        app:srcCompat="@drawable/input_background" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:fontFamily="@font/days_one"
        android:gravity="center_vertical"
        android:paddingLeft="10dp"
        android:text="Username"
        android:textColor="#747474"
        app:layout_constraintBottom_toBottomOf="@+id/imageView8"
        app:layout_constraintStart_toStartOf="@+id/imageView8"
        app:layout_constraintTop_toTopOf="@+id/imageView8" />
</androidx.constraintlayout.widget.ConstraintLayout>

You can achieve this using TextInputLayout with an editText inside it您可以使用 TextInputLayout 和其中的 editText 来实现这一点

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/username_text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/etUsername"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:ems="10"
        android:hint="Username" />

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

check this link at the headline called "Displaying Floating Label Feedback检查标题为“显示浮动 Label 反馈

https://guides.codepath.com/android/Working-with-the-EditText#displaying-floating-label-feedback https://guides.codepath.com/android/Working-with-the-EditText#displaying-floating-label-feedback

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何防止Android浮动EditText提示覆盖EditText中的文本? - How do I prevent Android floating EditText hint from covering the text in the EditText? 如何在Android Studio中更改提示文字的颜色? - How do you change hint text color in Android Studio? 如何在 Android 的 EditText 中将提示文本居中? - How do I center the hint text within an EditText in Android? 如何在 Android 中的 TextInputEditText 中顶部启动提示文本? - How do I top start the hint text within an TextInputEditText in Android? 如何减少文本提示和文本行之间的填充? - How do I reduce the padding between the text hint and text line? 当视图中有文本时,如何使android:hint不占用空间? - How do I make `android:hint` not take up space when there is text inside the view? 如何减少Android中浮动editText提示和editText框之间的空间? - How do you reduce space between floating editText hint and editText box in Android? 如何在 android 工作室中获取按钮的提示和文本 - How to get Hint and Text of a button In android studio 如何在EditText中居中并左对齐提示文本? - How do I center and left justifiy hint text in EditText? 如何在Android Studio中撤消logcat窗口的浮动模式 - How do you undo floating mode for the logcat window in Android Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM