为什么浮动提示动画不起作用?

时间:2019-08-04 10:27:12

标签: android xml android-layout android-animation android-textinputlayout

我需要像这样先制作动画:

enter image description here

(来自Internet的Gif)但即使使用app:hintAnimationEnabled="true",动画也无法正常工作。永远是gif的第二个示例。可能是什么问题呢?我在做什么错了?

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Login"
    app:hintEnabled="true"
    app:hintAnimationEnabled="true">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

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

1 个答案:

答案 0 :(得分:1)

您还需要为TextInputLayout设置提示以使动画正常工作,我只尝试动态设置提示以使其按预期工作,请尝试先在xml中设置提示以查看其是否起作用,如果不行,则可以它是动态的:

public class Yourapp extends Application implements Application.ActivityLifecycleCallbacks {

    private Activity currentActivity; 
    private Handler closecheckhandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                //do whatever you want
                default:
                    super.handleMessage(msg);
            }
        }
    };
    @Override
    public void onCreate() {
        super.onCreate();

        registerActivityLifecycleCallbacks(this);

    }

    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

    }

    @Override
    public void onActivityStarted(Activity activity) {

    }

    @Override
    public void onActivityResumed(Activity activity) {
        currentActivity = activity;

    }

    @Override
    public void onActivityPaused(Activity activity) {

    }

    @Override
    public void onActivityStopped(Activity activity) {

    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(Activity destroActivity) {
      if (currentActivity.equals(destroActivity)) {
            closecheckhandler.sendEmptyMessage(//Custom Code);
        } else {
            //do whatever you want
        }
    }
}