简体   繁体   中英

Android soft keyboard doesn't scroll and covers EditText when Window flag “LayoutNoLimits” is set

I want to have my gradient background extending up under the status bar. I can do it by setting the status bar color to transparent, and calling:

Window.AddFlags(WindowManagerFlags.LayoutNoLimits);

However, setting WindowManagerFlags.LayoutNoLimits stops the soft keyboard from scrolling the screen up, and the EditText views being edited are hidden under the keyboard.

I suggest you can use another way to make gradient background extending up under the status bar.

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:background="@drawable/gradient">    
<ScrollView  
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
         android:background="#fff">
   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_centerInParent="true">
    <LinearLayout
        android:fitsSystemWindows="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center"
        android:layout_marginBottom="10dp">
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="?android:attr/selectableItemBackground"
            android:src="@drawable/check">
            </ImageButton>
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="?android:attr/selectableItemBackground"
            android:src="@drawable/uncheck">
            </ImageButton>
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="?android:attr/selectableItemBackground"
            android:src="@drawable/icaon">
            </ImageButton>
        </LinearLayout>

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "11111111"/>
    <EditText
            android:id="@+id/edittext"
            android:layout_width="match_parent"
            android:imeOptions="actionGo"
            android:inputType="text"
            android:layout_height="wrap_content" />
  </LinearLayout>
</ScrollView>

gradient:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="135" android:startColor="#f56f2c" android:endColor="#fa9f46"/>
</shape>

protected override void OnCreate(Bundle savedInstanceState)
    {        
        if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Kitkat)
        {
            Window w = Window;

            w.AddFlags(WindowManagerFlags.TranslucentStatus);
            w.SetSoftInputMode(SoftInput.StateHidden | SoftInput.AdjustPan);
        }
        // Set our view from the "main" layout resource
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.layout2);

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM