2017-10-13 100 views
0

佈局在我的應用程序有以下佈局:鍵盤不壓以上的EditText

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <RelativeLayout 
      android:id="@+id/fragment_container" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

     <EditText 
      android:id="@+id/edit_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:background="@color/text" 
      android:gravity="center_horizontal" 
      android:hint="@string/input_hint" 
      android:inputType="textVisiblePassword" 
      android:padding="@dimen/margin" 
      android:singleLine="true" 
      android:textColor="@color/input_text" 
      android:textColorHint="@color/input_hint"> 
     </EditText> 

    </LinearLayout> 

當點擊EditText上,鍵盤按下屏幕了包括動作條,這樣的EditText只是在鍵盤上方。我想要的只是EditText坐在鍵盤上,但上面的FragmentContainer仍然保持完好「作爲背景」。我在AndroidManifest.xml文件中使用了android:windowSoftInputMode =「adjustResize」,但是我的應用程序是全屏的,並且該標記顯然不適用於全屏。

回答

2

據我所知,有沒有辦法實現你描述。

這些都可以給你的選擇爲windowSoftInputMode

  • adjustNothing:當鍵盤出現時,不調整窗口都沒有。這會阻止您的fragment_container被移動或調整大小,但也會導致鍵盤覆蓋您的文本輸入字段。

  • adjustResize:當鍵盤出現時,窗口會垂直「收縮」。這會導致您的fragment_container比鍵盤關閉時佔用的空間更少,可能會影響您的分段佈局。

  • adjustPan:當鍵盤出現時,屏幕被「推」向上。這會導致您的fragment_container的頂部被屏幕邊緣剪切。

  • adjustUnspecified:允許系統對上述三個選項中進行選擇。

下面是一些圖片,(希望)可以幫助說明這些屬性。

Keyboard closed

與鍵盤佈局關閉

Keyboard open; adjustNothing Keyboard open; adjustResize Keyboard open; adjustPan

從左至右:adjustNothingadjustResizeadjustPan