TextInputLayout not showing when View added programmatically

前端 未结 2 867
傲寒
傲寒 2021-01-04 07:59

I noticed some strange behaviour of TextInputLayout:

When I add the following to my layout:

    

        
相关标签:
2条回答
  • 2021-01-04 08:43

    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

    0 讨论(0)
  • 2021-01-04 08:48

    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);
    
    0 讨论(0)
提交回复
热议问题