TextInputLayout not showing when View added programmatically

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 17:59:06

You should change hint, not on EditText, but on TextInputLayout. So it will be:

TextInputLayout v = (TextInputLayout) LayoutInflater.from(this).inflate(R.layout.edittext_w_surrounding_textinputlayout, null);
v.setHint("Added programmatically");

TextInputLayout has it's own hint parameter and when inflating from layout it get's hint from it's child EditText and set empty hint on it.

When you want to change hint programatically you have to call textInputLayout.setHint(String text) instead of changing EditText hint

I use this ((FrameLayout) findViewById(R.id.framePreview)).addView(preview); with no issues at all, maybe its the view type? should this

ViewGroup root = (ViewGroup) findViewById(R.id.root);
root.addView(v);

not be this

LinearLayout root = (LinearLayout) findViewById(R.id.root);
root.addView(v);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!