2016-01-20 85 views
2

我正在研究android即時聊天應用程序。我已經成功實現了它的基本功能。現在我已經使用庫編譯「com.rockerhieu.emojicon:library:1.3.3」添加了一組表情符號。我在我的xml文件中使用FrameLayout來顯示圖釋。如何在表情符號鍵盤和軟鍵盤之間進行轉換

1 activity_chat.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FCAB26" 
    android:orientation="vertical" 
    android:weightSum="1"> 

    <ListView 
     android:id="@+id/list_view_messages" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight=".60" 
     android:background="@null" 
     android:divider="@null" 
     android:stackFromBottom="true" 
     android:transcriptMode="alwaysScroll"></ListView> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:layout_weight=".10" 
     android:orientation="horizontal" 
     android:weightSum="1"> 

     <ImageView 
      android:id="@+id/imgSmile" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".10" 
      android:src="@drawable/ic_msg_panel_smiles" 
      android:layout_gravity="center_vertical" 
      android:layout_marginRight="-10sp"/> 

     <com.rockerhieu.emojicon.EmojiconEditText 
      android:id="@+id/edtMessage" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:hint="Enter Message" 
      android:layout_weight=".60"></com.rockerhieu.emojicon.EmojiconEditText> 

     <Button 
      android:id="@+id/btnSendMessage" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:layout_weight=".30" 
      android:gravity="center" 
      android:onClick="onClick" 
      android:text="Send Message" /> 
    </LinearLayout> 

    <FrameLayout 
     android:id="@+id/emojicons" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight=".30" 
     android:visibility="gone" /> 

</LinearLayout> 

在這裏,就連指定的可見度走後,FrameLayout裏佔據一定的空間。

其顯示通過上述庫的表情符號的面板的代碼在下面給出:

// This method will set a panel of emoticons in the fragment 
private void setEmojiconFragment(boolean useSystemDefault) { 
    // Replacing the existing fragment having id emojicons with the fragment of emoticons library containing emoticons 
    getSupportFragmentManager().beginTransaction().replace(R.id.emojicons, EmojiconsFragment.newInstance(useSystemDefault)).commit(); 
} 

3.Screenshot

enter image description here

爲u可以在屏幕截圖看到,我有一個imageview,一個edittext和發送消息按鈕。點擊imageview,顯示錶情符號面板,並點擊edittext enoji鍵盤被隱藏,軟鍵盤顯示編輯。下面的代碼處理這個。

顯示錶情彈出:

public void showEmojiPopUp(boolean showEmoji) { 
    FrameLayout frameLayout = (FrameLayout) findViewById(R.id.emojicons); 
    frameLayout.setVisibility(View.VISIBLE); 
} 

隱藏softkeyboard:

public void hideKeyboard() { 
     InputMethodManager inputManager = (InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE); 
     inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
    } 

我的問題是,我想的表情符號鍵盤和軟鍵盤佔據.AT時間相等的空間只有一個應該是可見的。我想在表情符號鍵盤和軟鍵盤之間進行轉換。如你在代碼中看到的那樣,我在FrameLayout中添加了表情符號鍵盤。我無法使軟鍵盤和表情符號鍵盤的大小相等。請幫我解決這個問題。

編輯代碼: 我在我的代碼做了一些修改:

shoEmojiPopUp()方法:在這裏,我們正在調整的FrameLayout含有表情符號的面板高度,使軟鍵盤的高度和表情符號鍵盤是一樣的。

public void showEmojiPopUp(boolean showEmoji) { 
    Display display = getWindowManager().getDefaultDisplay(); 
    Point size = new Point(); 
    display.getSize(size); 
    deviceHeight = size.y; 
    Log.e("Device Height", String.valueOf(deviceHeight)); 
    frameLayout = (FrameLayout) findViewById(R.id.emojicons); 
    frameLayout.getLayoutParams().height = (int) (deviceHeight/2.5); // Setting the height of FrameLayout 
    frameLayout.requestLayout(); 
    frameLayout.setVisibility(View.VISIBLE); 
    hideKeyboard(); 
} 

2. hideKryboard()方法

// Hiding the keyboard 
public void hideKeyboard() { 
    InputMethodManager inputManager = (InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE); 
    inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
} 

它現在爲我工作。

+0

喜...你找到任何解決辦法?我有同樣的問題 –

+0

thanx很多.... –

+0

請告訴我它是否適合你。 –

回答

0

我使用這個代碼,我從這裏找到.... link

public Spannable parse(String text) { 
     CharSequence fromCache = cache.get(text); 
     if (fromCache != null) { 
      return (Spannable) fromCache; 
     } else { 
      CharSequence parsed = emoji.replaceEmoji(text); 
      Matcher matcher = userReference.matcher(text); 
      Spannable s; 
      if (parsed instanceof Spannable) { 
       s = (Spannable) parsed; 
      } else { 
       s = Spannable.Factory.getInstance().newSpannable(parsed); 
      } 

      while (matcher.find()) { 
       s.setSpan(new ForegroundColorSpan(0xff427ab0), matcher.start(), matcher.end(), 0); 
      } 
      cache.put(text, s); 

      return s; 
     } 
    }