안드로이드

[Android] 키보드 이벤트(Show/Hide)에 대해 알아보자

코딩하는후운 2022. 10. 20. 14:53
반응형

Android 키보드 이벤트(Show/Hide)에 대해 알아보자

 

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

		mLlEdit = (LinearLayout) findViewById(R.id.ll_edit);

		InputMethodManager controlManager = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);
		mSoftKeyboard = new SoftKeyboard(mLlEdit, controlManager);
		mSoftKeyboard.setSoftKeyboardCallback(new SoftKeyboard.SoftKeyboardChanged() {
					@Override
					public void onSoftKeyboardHide() {
						new Handler(Looper.getMainLooper())
								.post(new Runnable() {
									@Override
									public void run() {
										// 키보드 내려왔을때
									}
								});
					}

					@Override
					public void onSoftKeyboardShow() {
						new Handler(Looper.getMainLooper())
								.post(new Runnable() {
									@Override
									public void run() {
										// 키보드 올라왔을때
									}
								});
					}
				});

	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		mSoftKeyboard.unRegisterSoftKeyboardCallback();
	}

 

 

참조 :

https://tlshenm.tistory.com/33

반응형