title: How to handle keyboard behaviour for chat screen in android
body: <p>Below is the requirement for chat screen :
  1.) Show last message by default when the screen comes.
  2.) If I am on the last msg, and click inside message box, message box should be scrolled up and the last message should be shown above this box. Header shouldn't be gone. 
  3.) If I m in between the chat messages, and click inside message box, then only message box should be above side of keyboard, not the message list. Please keep in mind that header should be visible in all cases. Header is a RelativeLayout.</p>
  
  <p><strong>Below are some of the screens required to analyze the requirement :</strong></p>
  
  <p><a href="https://i.stack.imgur.com/jcCEy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jcCEy.png" alt="Chat screen and &quot;nd&quot; is last message"></a></p>
  
  <p><a href="https://i.stack.imgur.com/7lvKN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7lvKN.png" alt="Last message scrolls but header is not visible"></a></p>
  
  <p>Here is some portion of code I am doing to handle softkeypad behaviour:</p>
  
  <p>Here is the code related to :
  This is the code for sendbox OnClick :</p>
  
  <pre><code>case R.id.editEmojicon : {
  
                  if (messagesItems != null &amp;&amp; messagesItems.size() &gt; 0) {
                      currentMessageID = adapter.getCurrentMessageID();
                      lastMessageID = messagesItems.get(messagesItems.size() - 1).getMessageId();
  
                      if (lastMessageID.equalsIgnoreCase(currentMessageID))// i.e. We are on last message so scroll screen to last and last should be upside of message box
                      {
                          getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
                      } else // We are not on last message so don't scroll the screen
                      {
                          getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                      }
                      break;
                  }
  </code></pre>