For example, we should let us close an on-screen keyboard, after we log in successfully.
In that case, We can close the keybord programmatically.
==== MainActivity.java ====
package com.example.samplekeypad;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnCloseKeypad = (Button)findViewById(R.id.btnCloseKeyPad);
btnCloseKeypad.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
/**
* We can close the on-screen keyboard by using InputMethodManager.
*/
InputMethodManager inputManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
Toast.makeText(getBaseContext(), "스크린 키보드를 닫습니다.", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
: We can close an on-screen keyboard by calling hideSoftInputFromWindow() method in InputMethodManager Class.
'Android > ㄴ on-screen keyboard' 카테고리의 다른 글
Specifying The Keyboard Type (0) | 2014.02.07 |
---|