2015-09-29 29 views
1

我有一段用於用戶輸入的片段,當出現鍵盤時,我的片段屏幕甚至在狀態欄和工具欄上方移動。當鍵盤出現時,片段佈局與狀態欄重疊

沒有鍵盤 - https://www.dropbox.com/s/51gygn8z768bkp0/Screenshot_2015-10-01-15-26-37.png?dl=0

隨着Keyboad - 這個問題的 https://www.dropbox.com/s/z88pegbn7a0qoht/Screenshot_2015-10-01-15-26-44.png?dl=0

屏幕快照可以在上面分享圖像的URL中可以看出。 我正在嘗試使用半透明屏幕的應用程序。

我的活動佈局 -

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <!--<LinearLayout 
     android:id="@+id/container_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical">--> 

    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar" /> 
    <!-- </LinearLayout>--> 

    <FrameLayout 
     android:id="@+id/container_body" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" /> 


</LinearLayout> 


<fragment 
    android:id="@+id/fragment_navigation_drawer" 
    android:name="com.pace.automate.fragment.FragmentDrawer" 
    android:layout_width="@dimen/nav_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:layout="@layout/fragment_navigation_drawer" 
    tools:layout="@layout/fragment_navigation_drawer" /> 

,我使用的應用程序的主題是

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light"> 
     <item name="windowNoTitle">true</item> 
     <item name="windowActionBar">false</item> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="android:typeface">monospace</item> 

    </style> 

和工具欄就像是 -

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:fitsSystemWindows="true" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?attr/colorPrimary" 
    android:minHeight="?attr/actionBarSize" 
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

它具有屬性fitsSystemWindows = true。 但佈局正在向上移動,即使我已經試圖將片段佈局放入滾動視圖中,並在此活動的清單中設置android:windowSoftInputMode =「adjustPan」,但仍然在屏幕上顯示鍵盤時向上推。 我的片段佈局就像是

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:customAttrs="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 



    <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 

      > 
      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="8dp"> 


       <com.pace.automate.Utils.CustomFonts 
        android:id="@+id/title" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="16dp" 
        android:text="Please fill the Details" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="#898989" 
        customAttrs:customFont="regular" /> 

       <EditText 
        android:id="@+id/amount" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/title" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="12dp" 
        android:background="@android:color/transparent" 
        android:drawableBottom="@drawable/log_entry_keyline" 
        android:drawableLeft="@drawable/log_entry_icn_amount" 
        android:drawablePadding="7dp" 
        android:ems="10" 
        android:hint="Amount" 
        android:inputType="numberDecimal" 
        android:padding="4dp"> 

        <requestFocus /> 
       </EditText> 

       <EditText 
        android:id="@+id/odometer" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/amount" 
        android:layout_marginTop="12dp" 
        android:background="@android:color/transparent" 
        android:drawableBottom="@drawable/log_entry_keyline" 
        android:drawableLeft="@drawable/log_entry_icn_odometer" 
        android:drawablePadding="7dp" 
        android:ems="10" 
        android:hint="Odometer Reading" 
        android:inputType="number" 
        android:padding="4dp"> 


       </EditText> 

       <EditText 
        android:id="@+id/liters" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/odometer" 
        android:layout_marginTop="12dp" 
        android:background="@android:color/transparent" 
        android:drawableBottom="@drawable/log_entry_keyline" 
        android:drawableLeft="@drawable/measurement_volume_icon" 
        android:drawablePadding="7dp" 
        android:ems="10" 
        android:hint="Liters" 
        android:inputType="numberDecimal" 
        android:padding="4dp" /> 

       <TextView 
        android:id="@+id/calendar" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/liters" 
        android:layout_marginTop="12dp" 
        android:drawableBottom="@drawable/log_entry_keyline" 
        android:drawableLeft="@drawable/log_entry_icn_calendar" 
        android:drawablePadding="7dp" 
        android:ems="10" 
        android:hint="Date" 
        android:inputType="date" 
        android:padding="4dp" 
        android:textSize="16dp" /> 

       <CheckBox 
        android:id="@+id/fulltank" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_below="@+id/calendar" 
        android:layout_marginLeft="35dp" 
        android:layout_marginTop="20dp" 
        android:button="@drawable/custom_chekbox_fuel_enter" 
        android:paddingLeft="4dp" 
        android:text="Full Tank" /> 

       <CheckBox 
        android:id="@+id/partialtank" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignBaseline="@+id/fulltank" 
        android:layout_alignBottom="@+id/fulltank" 
        android:layout_alignParentRight="true" 
        android:layout_marginRight="35dp" 
        android:button="@drawable/custom_chekbox_fuel_enter" 
        android:checked="true" 
        android:paddingLeft="4dp" 
        android:text="Partial Tank" /> 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/partialtank" 
        android:layout_marginTop="12dp"> 

        <com.pace.automate.Utils.CustomAutoComplete 
         android:id="@+id/tag_station" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:layout_toLeftOf="@+id/pb_loading_indicator" 
         android:background="@android:color/transparent" 
         android:drawableBottom="@drawable/log_entry_keyline" 
         android:drawableLeft="@drawable/log_entry_icn_tag_station" 
         android:drawablePadding="7dp" 
         android:ems="10" 
         android:hint="Tag your Fuel station" 
         android:padding="4dp" /> 

        <ProgressBar 
         android:id="@+id/pb_loading_indicator" 
         style="?android:attr/progressBarStyleSmall" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentRight="true" 
         android:layout_centerVertical="true" 
         android:layout_gravity="center_vertical|right" 
         android:layout_marginRight="2dp" 
         android:visibility="gone" /> 
       </RelativeLayout> 


      </RelativeLayout> 
     </ScrollView> 

     <Button 
      android:id="@+id/saveFuelLogs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_marginTop="12dp" 
      android:background="#4cc1bb" 
      android:text="Save" 
      android:textColor="#fff" 
      android:textSize="@dimen/button_text_size" /> 

    </RelativeLayout> 

請幫我在這,它似乎很基本的錯誤,我在做什麼在這裏,但能不能短了出來。

Toolbar overlapping below status bar

Fragment overlaps my AppCompat toolbar

嘗試那種類似上述的建議,但仍然沒有找到解決辦法。

也明顯有這個活動的android:windowSoftInputMode =「adjustPan」。

+0

請將 機器人:windowSoftInputMode = 「adjustPan | stateUnchanged」 你的清單文件 –

+0

什麼都沒有改變與this.Still屏幕重疊的工具欄 –

+0

請把它設置在你的主要活動 –

回答

0

如果您的應用程序高於21 api級別,則可以使用以下代碼,但必須首先檢測鍵盤是否正在顯示。

hideStatusBar(true);要隱藏或hideStatusBar(false);顯示

public static void hideStatusBar(boolean isHide) { 
    final View decorView = UnationApplication.getInstance().getActivity().getWindow().getDecorView(); 

    final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE 
      | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
      | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 
      | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 

    if (isHide) { 
     int flagsMore = flags | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; 
     decorView.setSystemUiVisibility(flagsMore); 
    } else { 
     decorView.setSystemUiVisibility(flags); 
    } 

    decorView 
      .setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { 

       @Override 
       public void onSystemUiVisibilityChange(int visibility) { 
        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { 
         // decorView.setSystemUiVisibility(flags); 
        } 
       } 
      }); 
}