title: How do I handle switching between Emojipicker and Keyboard in Android?
body: <p>A functionality of the app I am working on is that people can chat with eachother. In the ChatFragment. I would like to have the same functionality as Whatsapp and Telegram where you can click the emoticon button and the keyboard switches to a Emojipicker <strong>Without</strong> any transition where the emoticonpicker has the same layout height as my keyboard (just like whatsapp and telegram). </p>
  
  <p>When I implemented it and switch from softwarekeyboard to emoji keyboard my softwarekeyboard would dissapear and the visibility of my emojipicker would be set from GONE to VISIBLE. Besides the ugly buggy transition because of the changing layout its also the same size accross all devices without keeping in mind that the keyboard have different heights. I am using the following emojipicker <a href="https://github.com/rockerhieu/emojicon" rel="nofollow">https://github.com/rockerhieu/emojicon</a></p>
  
  <p>Anyone know how to change my implementation in order for my emojipicker to be the same height as my keyboard? i tryed various things but none of the worked.. Below some code from my chatfragment and layout.</p>
  
  <p><strong>ChatFragment</strong></p>
  
  <pre><code>public class ChatFragment extends W3SFragment implements IResultListener  {
  
      private int chatContactId;
      private Context context;
      private DatabaseHelper databaseHelper;
      private InputMethodManager inputManager;
  
      private View fragmentView;
      private TextView statusText;
  
      private ImageView emojiconIconImageView;
      private View emojiconViewContainer;
  
      private ChatContact chatContact;
  
      public EmojiconEditText emojiconEditText;
  
  
      public ChatFragment(int chatContactId) {
  
          this.chatContactId = chatContactId;
          databaseHelper = new DatabaseHelper();
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          this.context = getActivity();
          getSherlockActivity().getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
  
          inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
          getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          fragmentView = inflater.inflate(R.layout.chat_main, null);
          FragmentManager fm = getChildFragmentManager();
          FragmentTransaction ft = fm.beginTransaction();
  
          Fragment emojiconsFragment = new EmojiconsFragment();
          ft.replace(R.id.emojiconsContainer, emojiconsFragment);
          ft.commit();
  
          return fragmentView;
      }
  
  
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          statusText = (TextView) fragmentView.findViewById(R.id.ChatStatusText);
  
          emojiconEditText = (EmojiconEditText) fragmentView.findViewById(R.id.editMessage);
          emojiconEditText.requestFocus();
  
          emojiconIconImageView = (ImageView) fragmentView.findViewById(R.id.chatSmileyIcon);
          emojiconIconImageView.setOnClickListener(new OnEmojiconIconClickListener());
  
  
          emojiconViewContainer = fragmentView.findViewById(R.id.emojiconsContainer);
          emojiconViewContainer.setVisibility(View.GONE);
  
          setkeyboardLayoutListeners();
          setContactLayout();
      }
  
      public void setContactLayout() {
          ChatContact chatContact = databaseHelper.getContact(chatContactId);
          if(chatContact != null) {
  
              setStatusMessage(chatContact.Status);
              getSherlockActivity().setTitle(chatContact.Name);
              if(chatContact.Picture != null) {
                  Bitmap l_bTmp = CommonUtilities.getSquareImage(CommonUtilities.createBitmapFromImageLocation(mStrBasePath + chatContact.Picture));
                  Bitmap l_bmpOverlay = BitmapFactory.decodeResource(context.getResources(), R.drawable.image_round_overlay_darkgrey);
  
                  getSherlockActivity().getSupportActionBar().setIcon(CommonUtilities.createDrawableFromBitmap(getSherlockActivity().getApplicationContext(), CommonUtilities.overlay(l_bTmp, l_bmpOverlay)));
              }
          }
      }
  
      public void setStatusMessage(String message) {
          if(message != null &amp;&amp; message.equals(""))
              message = getResources().getString(R.string.chat_status_default);
  
          statusText.setText(message);
      }
  
      @Override
      public void onResultSucceeded(String p_strResult) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void onProgress(Integer p_IntProgress) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void GotInternetBack() {
          // TODO Auto-generated method stub
  
      }
  
      public static void onAttachmentclick(MainActivity mainActivity) {
          // TODO Auto-generated method stub
  
      }
  
      private void changeKeyboardLayout(boolean showEmoticons) {
          if(showEmoticons) {
              inputManager.hideSoftInputFromWindow(emojiconEditText.getWindowToken(), 0);
              emojiconViewContainer.setVisibility(View.VISIBLE);
              emojiconIconImageView.setImageResource(R.drawable.ic_action_keyboard);
          } else {
              inputManager.showSoftInput(emojiconEditText, 0);
              emojiconViewContainer.setVisibility(View.INVISIBLE);
              emojiconIconImageView.setImageResource(R.drawable.smiley_icon);
          }
      }
  
      private void setkeyboardLayoutListeners() {
          emojiconEditText.setOnTouchListener(new OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                  changeKeyboardLayout(false);
                  return false;
              }
          });
          emojiconEditText.setKeyImeChangeListener(new KeyImeChange() {
  
              @Override
              public void onKeyIme(int keyCode, KeyEvent keyEvent) {
                  if(keyEvent.getAction() == KeyEvent.ACTION_UP &amp;&amp; keyCode == KeyEvent.KEYCODE_BACK) {
                      closeKeyboardLayout();
                  }
              }
          });
      }
  
  
      private void closeKeyboardLayout()
      {
          inputManager.hideSoftInputFromWindow(emojiconEditText.getWindowToken(), 0);
          emojiconViewContainer.setVisibility(View.GONE);
          emojiconIconImageView.setImageResource(R.drawable.smiley_icon);
      }
  
      private class OnEmojiconIconClickListener implements OnClickListener {
  
          @Override
          public void onClick(View arg0) {
              if(emojiconViewContainer.getVisibility() == View.VISIBLE) {
                  changeKeyboardLayout(false);
              } else {
                  changeKeyboardLayout(true);
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>chat_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:emojicon="http://schemas.android.com/apk/res-auto"
      android:id="@+id/chatMainRoot"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;LinearLayout
          android:id="@+id/statusHold"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          android:background="@color/lightgrey"
          android:gravity="center" &gt;
  
          &lt;TextView
              android:id="@+id/ChatStatusText"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="left"
              android:text="@string/chat_status_default"
              android:textStyle="italic" 
              android:textColor="#777777"
              android:maxLines="1"
              android:ellipsize="end"
              android:padding="10dp" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;ListView
          android:id="@+id/Messages"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_below="@+id/statusHold"
          android:layout_above="@+id/writerLayout" /&gt;
  
      &lt;LinearLayout
          android:id="@+id/writerLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:orientation="vertical" &gt;
  
          &lt;LinearLayout
              android:id="@+id/chatSentMessageHolder"
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:background="@drawable/border_grey"
              android:orientation="horizontal"
              android:padding="5dp" &gt;
  
              &lt;ImageView
                  android:id="@+id/chatSmileyIcon"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  android:src="@drawable/smiley_icon" /&gt;
  
              &lt;com.rockerhieu.emojicon.EmojiconEditText
                  android:id="@+id/editMessage"
                  android:layout_width="0dip"
                  android:layout_height="match_parent"
                  android:layout_marginLeft="5dp"
                  android:layout_marginRight="10dp"
                  android:layout_marginTop="1dp"
                  android:layout_weight="0.1"
                  android:background="@drawable/et_selector"
                  emojicon:emojiconSize="28sp"
                  android:ems="10"
                  android:hint="@string/chat_default_message_sent_text"
                  android:inputType="text"/&gt;
  
              &lt;ImageView
                  android:id="@+id/chatSentMessageIcon"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  android:background="@drawable/chat_sent_icon" /&gt;
          &lt;/LinearLayout&gt;
  
          &lt;!-- Layout to inflate the emojicons in --&gt;
          &lt;LinearLayout 
              android:id="@+id/emojiconsContainer"
              android:layout_width="match_parent"
              android:layout_height="220dp"
              android:orientation="vertical"/&gt;
      &lt;/LinearLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>In ChatFragment I set the SoftInputMode to SOFT_INPUT_ADJUST_NOTHING because i tryed to load the emotoji keyboard behind my softwarekeyboard which works very very good. The only problem I had once again was the height of the emojipicker. When i tested it on my Galaxy s3 the size was the same as the keyboard, on my nexus 5 and Galaxy Y DUO the layout was a bit bigger and smaller then the keyboard layout so that the invisible emojipicker sticked out of the software keyboard...</p>
  
  <p>Does anyone have any tips on how I can succesfully implement this without getting weird layout glitches or animations?</p>