2014-06-24 1 views

답변

16

시도 : -

// 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?

+0

첫 번째는 하드 키보드 작동합니다. 두 번째는 할 수 없습니다. 어떻게 onMeasure (int, int)를 재정의 할 수 있습니까? – AlexanderNajafi

+0

@alexandernajafi 우선 먼저 늦은 답신으로 인해 유감스럽게 생각합니다. keyborad를 탐지하는 몇 가지 방법이 있으므로 위의 방법을 사용하거나 링크를 참조하십시오. – duggu

관련 문제