[안드로이드,Android]키보드 보이기, 숨기기
2013. 1. 28. 09:40ㆍMobile/Android
반응형
package com.example.ggari_keyboard;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
InputMethodManager Imm;
Button btnShow;
Button btnHide;
EditText et01;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
et01 = (EditText) findViewById(R.id.et01);
btnShow = (Button) findViewById(R.id.btnShow);
btnHide = (Button) findViewById(R.id.btnHide);
btnShow.setOnClickListener(btnOnClick);
btnHide.setOnClickListener(btnOnClick);
}
OnClickListener btnOnClick = new Button.OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnShow:
Imm.showSoftInput(et01, 0);
break;
case R.id.btnHide:
Imm.hideSoftInputFromWindow(et01.getWindowToken(), 0);
break;
}
}
};
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="@+id/et01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:hint="입력해주세요" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btnShow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="키보드 보이기" />
<Button
android:id="@+id/btnHide"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="키보드 숨기기" />
</LinearLayout>
</RelativeLayout>
반응형
'Mobile > Android' 카테고리의 다른 글
| [안드로이드,Android]WebView,웹뷰 (1) | 2013.02.05 |
|---|---|
| [안드로이드]프로그레스바,ProgressBar (0) | 2013.01.30 |
| [안드로이드,Android]로그,LOG (0) | 2013.01.25 |
| [안드로이드,Android]메뉴 옵션 (0) | 2013.01.24 |
| [안드로이드,Android]타이머 Timer (0) | 2013.01.23 |