2014-11-02 107 views
0

我實現了ankushsachdeva emojicon project以在我的聊天應用程序中顯示emojicons。當我點擊特定聊天時,我開始聊天活動。如果我再立即點擊表情符號,ImageButton的,我做,而無需首先擴大了鍵盤,它看起來像左邊的屏幕截圖hereankushsachdeva emojicon通過軟鍵盤顯示(Android)

後記中,emojicon疊加是總是正確顯示。 (右鍵截圖)

我希望疊加層總能像右邊截圖一樣。有任何想法嗎? (在此先感謝)

ChatActivity:

private ListView listView; //contains the chatmessages and has a customAdapter 
private EmojiconsPopup popUp; //emojicon-popUp 
private EditText editText; //editText to capture text and emojicons 
private InputMethodManager inputManager; 

@Override 
protected void onCreate(Bundle savedInstanceState){ 
    listView = (ListView) findViewById(R.id.listView); 

    //...// 

    inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 

    popUp = new EmojiconsPopup(listView, getApplicationContext()); 

    popUp.setSizeForSoftKeyboard(); 

    popUp.setOnEmojiconClickedListener(new OnEmojiconClickedListener(){ 
     @Override 
     public void onEmojiconClicked(Emojicon emojicon){ 
      editText.append(emojicon.getEmoji()); 
     } 
    }); 


    popUp.setOnEmojiconBackspaceClickedListener(new OnEmojiconBackspaceClickedListener(){ 
     @Override 
     public void onEmojiconBackspaceClicked(View v){ 
      KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL); 
      editText.dispatchKeyEvent(event); 
     } 
    }); 

    popUp.setOnSoftKeyboardOpenCloseListener(new OnSoftKeyboardOpenCloseListener(){ 
     @Override 
     public void onKeyboardOpen(int keyBoardHeight){ 
     } 
     @Override 
     public void onKeyboardClose(){ 
      if (popUp.isShowing()) 
       popUp.dismiss(); 
     } 
    }); 
} 

//called when the emojicon button is clicked 
public void onEmojiButtonClicked(View view){ 
    if (!popUp.isShowing()){ 
     inputManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
     popUp.showAtBottom(); //show popUp with emojicons 
    }else if(popUp.isShowing()){ 
     popUp.dismiss(); // hide popUp with emojicons 
    } 
} 

回答

0

因爲,有知道的軟鍵盤高度沒有可靠的方法,該庫通過打開鍵盤,看到計算多少最頂部的佈局的看法,水平縮小。

我已經在庫showAtBottomPending()中添加了一個新函數,它可以解決您的問題。 對您的代碼進行以下兩項更改。

  1. 更改您的onEmojiButtonClicked功能

    public void onEmojiButtonClicked(View view){ 
        if (!popUp.isShowing()){ 
         popUp.showAtBottomPending(); //show popUp with emojicons after the keyboard is visible 
         inputManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
        }else if(popUp.isShowing()){ 
         popUp.dismiss(); // hide popUp with emojicons 
        } 
    } 
    
  2. 不是傳遞的ListView在EmojiconsPopup構造, 通過您的視圖層次的最上面的佈局。
+0

工程就像一個魅力,謝謝! – mtosch 2015-04-06 16:02:04

0

像這樣使用它的工作。

public void onEmojiButtonClicked(View view){ 
if (!popUp.isShowing()){ 
    popUp.showAtBottomPending(); //show popUp with emojicons after the keyboard is visible 
    showKeyboard(ettext); 
}else if(popUp.isShowing()){ 
    popUp.dismiss(); // hide popUp with emojicons 
} 
} 


public void showKeyboard(final EmojiconEditText ettext){ 
      ettext.requestFocus(); 
      ettext.postDelayed(new Runnable(){ 
      @Override public void run(){ 
       InputMethodManager keyboard=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
       keyboard.showSoftInput(ettext,0); 
      } 
      } 
     ,200); 
     }