如何以编程方式使用OutlineBox创建TextInputLayout [英] How to create TextInputLayout with OutlineBox programmatically

查看:141
本文介绍了如何以编程方式使用OutlineBox创建TextInputLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Widget.MaterialComponents.TextInputLayout.OutlinedBox样式创建TextInputLayout.我尝试了许多方法,但无法获得所需的结果. 这是我的代码.

I want to create TextInputLayout with Widget.MaterialComponents.TextInputLayout.OutlinedBox style. I tried many ways but couldn't get the required result. Here is my code.

TextInputLayout textInputLayout = new TextInputLayout(getActivity(),null,R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox);
textInputLayout.setHint("My Hint");
TextInputEditText editText = new TextInputEditText(textInputLayout.getContext());
textInputLayout.addView(editText);
parentView.addView(textInputLayout);

我也尝试过:

TextInputLayout textInputLayout = new TextInputLayout(getActivity(),null,TextInputLayout.BOX_BACKGROUND_OUTLINE);

我想创建这样的视图.

I want to create view like this .

推荐答案

更新

感谢@MikeM.

您需要使用 TextInputLayout.setBoxBackgroundMode() 方法以使用OutlineBox样式

You need to use TextInputLayout.setBoxBackgroundMode() method to use OutlineBox style

setBoxBackgroundMode (int boxBackgroundMode)

setBoxBackgroundMode (int boxBackgroundMode)

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆