TextInputLayout not showing EditText hint before user focus on it

后端 未结 16 938
时光说笑
时光说笑 2020-11-27 13:50

I am using recently released Android Design Support Library to show floating label with EditTexts. But i am facing the problem that the Hint on the EditText is not showing w

16条回答
  •  遥遥无期
    2020-11-27 13:53

    I solved my problem with this code:

    new Handler().postDelayed(
            new Runnable() {
                @Override
                public void run() {
                    TextInputLayout til = (TextInputLayout) someParentView.findViewById(R.id.til);
                    til.setHint("Your Hint Text");
                    til.bringToFront();
                }
            }, 10);
    

    The key here is the bringToFront. It forces the TextInputLayout to redo its drawing, which is not the same as doing invalidate(). If you are trying to display the TextInputLayout on a view that has animations or tranistions, you need to execute the above code at the end of the animation or transition. Just make sure that the code above runs on the UI thread.

提交回复
热议问题