How to move the hint of EditText (Android Java) to the top of the view while typing? I have attached 2 images to show how I want to implement my EditText View.
How to make search country
hint at the top of view as per the image?
Please help!
How to move the hint of EditText (Android Java) to the top of the view while typing? I have attached 2 images to show how I want to implement my EditText View.
How to make search country
hint at the top of view as per the image?
Please help!
Using TextInputLayout
you can achieve this.
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/searchCountriesInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/searchCountriesEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search Countries" />
</com.google.android.material.textfield.TextInputLayout>
In build.gradle
:
dependencies {
implementation 'com.google.android.material:material:1.1.0'
}
You can user TextInputLayout for this :-
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilSearchCountry"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_normal"
android:hint="@string/your_hint"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etSearchCountry"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
In case if you haven't included google material library add this in your build.gradle:
dependencies {
implementation 'com.google.android.material:material:1.1.0'
}