16
키보드를 표시하거나 숨길 때 발생하는 이벤트를 수신하려고합니다. 안드로이드에서 가능합니까? 나는 내 활동을 시작할 때 키보드가 보이거나 숨겨져 있는지 알아 내려고하지 않고, 나는 이벤트를 듣고 싶다. 코드 아래키보드 듣기 android에서 이벤트 표시 또는 숨기기
키보드를 표시하거나 숨길 때 발생하는 이벤트를 수신하려고합니다. 안드로이드에서 가능합니까? 나는 내 활동을 시작할 때 키보드가 보이거나 숨겨져 있는지 알아 내려고하지 않고, 나는 이벤트를 듣고 싶다. 코드 아래키보드 듣기 android에서 이벤트 표시 또는 숨기기
시도 : -
// from the link above
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks whether a hardware keyboard is available
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
} else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
}
}
또는
boolean isOpened = false;
public void setListnerToRootView(){
final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard.
Toast.makeText(getApplicationContext(), "Gotcha!!! softKeyboardup", 0).show();
if(isOpened == false){
//Do two things, make the view top visible and the editText smaller
}
isOpened = true;
}else if(isOpened == true){
Toast.makeText(getApplicationContext(), "softkeyborad Down!!!", 0).show();
isOpened = false;
}
}
});
}
또는
코드 아래에 당신이있는 LinearLayout를 확장 할 필요를 위해
.@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int proposedheight = MeasureSpec.getSize(heightMeasureSpec);
final int actualHeight = getHeight();
if (actualHeight > proposedheight){
// Keyboard is shown
} else {
// Keyboard is hidden
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
은 아래 링크를 참조하십시오 -
How to capture the "virtual keyboard show/hide" event in Android?
첫 번째는 하드 키보드 작동합니다. 두 번째는 할 수 없습니다. 어떻게 onMeasure (int, int)를 재정의 할 수 있습니까? – AlexanderNajafi
@alexandernajafi 우선 먼저 늦은 답신으로 인해 유감스럽게 생각합니다. keyborad를 탐지하는 몇 가지 방법이 있으므로 위의 방법을 사용하거나 링크를 참조하십시오. – duggu