2016-04-25 22 views

回答

0

如發現here,您需要實例化SoftkeyBoard並添加一個偵聽器。

/* 
Somewhere else in your code 
*/ 

RelativeLayout mainLayout = findViewById(R.layout.main_layout); // You must use your root layout 
InputMethodManager im = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);  

/* 
Instantiate and pass a callback 
*/ 

SoftKeyboard softKeyboard; 
softKeyboard = new SoftKeyboard(mainLayout, im); 
softKeyboard.setSoftKeyboardCallback(new SoftKeyboard.SoftKeyboardChanged() 
{ 
@Override 
    public void onSoftKeyboardHide() 
    { 
     // Code here 
    } 

    @Override 
    public void onSoftKeyboardShow() 
    { 
     // Code here 
    } 
});  

/* 
Open or close the soft keyboard programatically 
*/ 

softKeyboard.openSoftKeyboard(); 
softKeyboard.closeSoftKeyboard(); 


/* 
SoftKeyboard can catch keyboard events when an EditText gains focus and keyboard appears 
*/ 


/* Prevent memory leaks: 
*/ 

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

在他的文章中,您還可以找到更多關於錯誤修復和可能問題的信息。

0

添加onGlobalLayoutListener到活動/片段的父視圖,使您的按鈕知名度相應

final View parentView= findViewById(R.id.myrootview); 
     parentView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
     @Override 
     public void onGlobalLayout() { 
      int heightDiff = root.getRootView().getHeight() - root.getHeight(); 

      Rect rectgle= new Rect(); 
      Window window= getWindow(); 
      window.getDecorView().getWindowVisibleDisplayFrame(rectgle); 
      int contentViewTop= 
       window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); 

      if(heightDiff <= contentViewTop){ 
       //Soft KeyBoard Hidden---button visible 

      }else{ 
       //Soft KeyBoard Shown---button hide 
      } 


     } 
    });