Android Edittext Hint

Android EditText Hint

I don't know whether a direct way of doing this is available or not, but you surely there is a workaround via code: listen for onFocus event of EditText, and as soon it gains focus, set the hint to be nothing with something like editText.setHint(""):

This may not be exactly what you have to do, but it may be something like this-

myEditText.setOnFocusListener(new OnFocusListener(){
public void onFocus(){
myEditText.setHint("");
}
});

EditText with hint, where hint moves

if you mean this

Sample Image

it is TextInputLayout

Add the dependency for the design support library inside the build.gradle (Module: app) file as shown below.

implementation 'com.google.android.material:material:<version>'

the latest version at this time is 1.2.0-alpha03 you can see latest version from mvnrepository

Then, you can use it like this in your xml layouts.

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

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/my_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/YOUR_HINT"
android:singleLine="true"
android:textColor="@color/colorDarkestGray" />
</com.google.android.material.textfield.TextInputLayout>

Change EditText hint color when using TextInputLayout

Looks like the parent view had a style for a 3rd party library that was causing the EditText to be white.

android:theme="@style/com_mixpanel_android_SurveyActivityTheme"

Once I removed this everything worked fine.

Edit Text Hint is not visible in android studio design preview but is visible on emulator when app runs

This is usually the case with edittext.
Change the background of the edittext to white and it should display in the layout editor too.
If it doesn't, check the hint text colour.

Shifting edit text hints with android studio

You can use drawablePadding property:

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@android:drawable/star_big_on"
android:drawablePadding="10dp"
android:hint="Username"/>

Result:

Sample Image



Related Topics



Leave a reply



Submit