我在使用 EditText 控件时遇到问题,并且不确定如何将其完全隐藏。我的要求是使用 InputMethodManager 和 showSoftInput 始终默认为字母数字键盘从 webview 控件显示数字 SIP。所以我创建了一个隐藏的 EditText 控件并更改了该控件的输入类型并且它工作正常但问题是隐藏的控件仍然可以访问并且它始终显示在上/左角。有没有办法将隐藏的 EdiTtext 与我正在编辑的控件完全移动/对齐并完全隐藏它。
InputMethodManager imm;
if (mWebEditText == null)
{
mWebEditText = new WebEditText(Common.mainActivity.getApplicationContext(),view.getView());
}
mWebEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
mWebEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
AbsoluteLayout webEditTextPanel = (AbsoluteLayout) Common.mainActivity.findViewById(R.id.editext_panel);
webEditTextPanel.removeAllViews();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(area.width(), area.height());
lp.leftMargin = area.left;
lp.topMargin = area.top;
webEditTextPanel.addView(mWebEditText, lp);
mWebEditText.setVisibility(View.VISIBLE);
mWebEditText.setCursorVisible(false);
mWebEditText.setBackgroundColor(0x00FFFFFF); // If I do this the bounding rectangle is hidden but if we tap on top/left corner then we can see the edit box
mWebEditText.requestFocus();
imm.showSoftInput(mWebEditText, 0);
EditText 定义:
<AbsoluteLayout android:id="@+id/editext_panel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="false" android:focusableInTouchMode="false" android:visibility="visible">
</AbsoluteLayout>
截图:
最佳答案
如果您想隐藏,请使用 editText.setVisibility(View.INVISIBLE)
如果您希望它完全消失并且在 UI 中没有分配空间,请使用命令 editText。设置可见性(View.GONE)
关于android - 如何完全隐藏用于将输入类型更改为数字 SIP 的 EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14623672/