简体   繁体   English

当设置了Window标志“LayoutNoLimits”时,Android软键盘不会滚动并覆盖EditText

[英]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. 但是,设置WindowManagerFlags.LayoutNoLimits阻止软键盘向上滚动屏幕,并且正在编辑的EditText视图将隐藏在键盘下方。

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);

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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