-2

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>
Shay Kin
  • 2,539
  • 3
  • 15
  • 22

1 Answers1

1

You can achieve this using TextInputLayout with an editText inside it

<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

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

  • Okay, thank you. I put that in but when I try to run the emulator to check it, it's telling me that the image I used in my "ImageView" needs to have a file name ending in .xml and I'm not sure how to fix that? – Destiny Bullard May 05 '21 at 00:28
  • Drawable files in android must have extensions of .png .jpg .gif .XML if you want to supply an Image make sure it's either .png or .jpg and if it's already in of those to extensions rename the file to end with .png or .jpg – Khaled Sabri May 05 '21 at 04:04
  • you might also want to check this similar question https://stackoverflow.com/questions/41011739/error-the-file-name-must-end-with-xml-or-png – Khaled Sabri May 05 '21 at 04:05
  • If this answer worked for you, please mark the answer as the accepted answer – Khaled Sabri May 08 '21 at 23:58