【问题标题】:How to completely hide the EditText that is used to change input type to numeric SIP如何完全隐藏用于将输入类型更改为数字 SIP 的 EditText
【发布时间】:2013-01-31 10:33:39
【问题描述】:

我在使用 EditText 控件时遇到问题,不知道如何将其完全隐藏。我的要求是使用 InputMethodManager 从 webview 控件显示数字 SIP,并且 showSoftInput 始终默认为字母数字键盘。所以我创建了一个隐藏的 EditText 控件并更改了该控件的输入类型,它工作正常,但问题是隐藏控件仍然可以访问,并且它始终显示在左上角/左上角。有没有办法将隐藏的 EditTtext 与我正在编辑的控件完全移动/对齐并完全隐藏它。

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>

截图:

【问题讨论】:

  • 你试过将背景颜色设置为透明吗?
  • @AND_DEV,请在代码中查看我的 cmets mWebEditText.setBackgroundColor(0x00FFFFFF); // 如果我这样做,边界矩形是隐藏的,但是如果我们点击左上角,那么我们可以看到编辑框

标签: android input android-edittext sip numeric


【解决方案1】:

如果你想隐藏使用editText.setVisibility(View.INVISIBLE),如果你想它完全消失并且在UI中没有分配空间,那么使用命令editText.setVisibility(View.GONE)

【讨论】:

  • 如果我使用 INVISIBLE 或 GONE 选项,那么当我点击控件时我不会收到 SIP。仅当可见性设置为可见时,我才能获得 SIP
【解决方案2】:

将控件移出屏幕效果很好。即控件被隐藏并且数字 SIP 弹出很好。

AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams(area.width(), area.height(), -200, -200);

【讨论】:

    猜你喜欢
    • 2017-02-13
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 2018-01-25
    相关资源
    最近更新 更多