2016-09-22 25 views
2

我已經創建了一個聊天應用程序。我附上了截圖。當鍵盤處於活動狀態時,工具欄不可見。我已經嘗試了堆棧溢出和其他網站上的各種解決方案,但似乎沒有爲我工作。我附上了代碼。請幫忙。 1.layout代碼:如何在出現軟鍵盤時將工具欄固定在頂部

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/main_content" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <RelativeLayout 
     android:id="@+id/layout_chat_container" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     tools:ignore="RtlHardcoded" 
     android:layout_gravity="bottom" 
     android:isScrollContainer="false" 
     android:background="@color/newColor2"> 

     <include 
      android:id="@+id/app_bar" 
      layout="@layout/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/toolbar_height" /> 
     <se.emilsjolander.stickylistheaders.StickyListHeadersListView 
      android:id="@+id/list_chat_messages" 
      style="@style/ListViewWithoutDividerStyle" 
      android:listSelector="@android:color/transparent" 
      android:fastScrollEnabled="true" /> 
     <ProgressBar 
      android:id="@+id/progress_chat" 
      style="@style/CenterProgressBarStyle" 
      android:visibility="gone" /> 

     <LinearLayout 
      android:id="@+id/layout_attachment_preview_container" 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_above="@+id/layout_chat_send_container" 
      android:background="@color/colorPrimary" 
      android:orientation="vertical" 
      android:visibility="gone"> 
      <View 
       android:id="@+id/divider_chat_attachments" 
       style="@style/HorizontalDividerStyle" /> 

      <com.flock.android.quickblox.chat.ui.widget.AttachmentPreviewAdapterView 
       android:id="@+id/adapter_view_attachment_preview" 
       style="@style/MatchWidth" /> 
     </LinearLayout> 
     <View 
      android:id="@+id/divider_chat" 
      style="@style/HorizontalDividerStyle" 
      android:layout_above="@+id/layout_chat_send_container" /> 
     <LinearLayout 
      android:id="@+id/layout_chat_send_container" 
      style="@style/MatchWidth" 
      android:layout_alignParentBottom="true" 
      android:background="@color/colorPrimary" 
      android:orientation="horizontal"> 
      <ImageButton 
       android:id="@+id/button_chat_attachment" 
       style="@style/BorderlessImageButtonStyle" 
       android:contentDescription="@null" 
       android:layout_gravity="center_vertical" 
       android:onClick="onAttachmentsClick" 
       android:src="@mipmap/ic_action_attachment" 
       android:visibility="gone" /> 
      <EditText 
       android:id="@+id/edit_chat_message" 
       style="@style/WeightWidth" 
       android:layout_height="wrap_content" 
       android:hint="@string/chat_edit_text_hint" 
       android:scrollHorizontally="false" 
       android:textColorHint="@color/colorActionMode" 
       android:inputType="textShortMessage|textMultiLine|textCapSentences" 
       android:maxLength="1024" 
       android:textColor="@color/white" 
       android:layout_marginLeft="@dimen/view_margin_small" 
       android:singleLine="false" /> 
      <ImageButton 
       android:id="@+id/button_chat_send" 
       style="@style/BorderlessImageButtonStyle" 
       android:contentDescription="@null" 
       android:layout_gravity="center_vertical" 
       android:onClick="onSendChatClick" 
       android:src="@mipmap/ic_sent" 
       android:text="@string/chat_send" /> 
     </LinearLayout> 
    </RelativeLayout> 
</android.support.design.widget.CoordinatorLayout> 

2.Screenshots:
Before After

+0

_i已嘗試各種解決方案堆棧overflow_你試過了什麼?我在代碼中看不到。你嘗試用'android:windowSoftInputMode =「stateHidden | adjustPan」' – Piyush

+0

我試試這個,但不能工作...

回答

2

嘗試下面的代碼,並確保你的佈局是在滾動型爲adjustResize總是調整活動的主窗口,使屏幕上軟鍵盤的空間。

<activity 
     android:name=".YourActivity" 
     android:windowSoftInputMode="stateHidden|adjustResize"> 
+0

我也嘗試這也..但不能工作.. –

+0

你能找到任何其他答案爲該que ... –

0

刪除標誌getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);全屏活動,如果你在你的代碼有

檢查,你應該在你的清單活動標記有android:windowSoftInputMode="stateHidden|adjustResize"

現在嘗試...希望它有幫助

+0

謝謝,但我已經試過這個...是不能解決我的問題.... –

+0

你能找到任何其他的答案,爲那個問題... –

+0

我有同樣的問題,並給出解決方案只解決了我的問題...在你的情況下,如果它不解決你的問題,然後嘗試設置** setActionBar **與工具欄和xml嘗試給下面(@ + id/app_bar)屬性到StickyListHeadersListView ... – Priya

相關問題