简体   繁体   中英

How to Apply an Animation for the EditText's hint?

i am changing an EditText's hint through java by editText.setHint(" "); ,

how can i apply a transition or animation to the hint text when it's changed?

what am trying to do is like this, but for the hint text when i change it in java code https://i.stack.imgur.com/SuBAM.gif

Use Floating hint EditText:

In gradle add

compile 'com.android.support:design:22.2.0'

use TextInputLayout in xml layout should like this

<android.support.design.widget.TextInputLayout
android:id="@+id/tilayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">

    <EditText
        android:id="@+id/editText"
       ------
        android:hint="yourhint"/>
</android.support.design.widget.TextInputLayout>

add compile 'com.android.support:design:24.2.0' in gradle dependencies

use TextInputLayout for animation in xml

<android.support.design.widget.TextInputLayout
        android:id="@+id/textInputServer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="36dp"
        app:errorTextAppearance="@style/TextErrorAppearance">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ........./>
    </android.support.design.widget.TextInputLayout>

i performed an animation to the editText by:

hintTextTransition = AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_out_right);

editText.startAnimation(hintTextTransition);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM