English 中文(简体)
安卓隐藏软键盘输入法[关闭]
原标题:Android hide soft keyboard IME [closed]
  • 时间:2010-10-25 00:04:25
  •  标签:
  • java
  • android

下面是我设法在android上隐藏软键盘的一些代码。它的工作原理是用户点击屏幕上的任何位置(EditText输入之外)来隐藏输入法软键盘。它将OnTouchListener注册到ScrollView(id=“@+id/sv_background),当触摸屏幕时,它会通过InputMethodManager代码隐藏IME软键盘。在这种情况下,我已将滚动视图设置为父布局,但它也适用于任何其他布局视图。

我希望这对安卓领域的人有用。

XML语言

<ScrollView 
android:id="@+id/sv_background" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android">

   <other views and EditTexts/>

</ScrollView>

Java语言

private ScrollView svBackground;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newentry);

    svBackground = (ScrollView)findViewById(R.id.sv_background);
    svBackground.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(svBackground.getWindowToken(), 0);
            return false;
        }
    });
}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签