键盘附带底片片段 [英] Bottom Sheet Fragment comes up with keyboard

查看:96
本文介绍了键盘附带底片片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在底部工作表片段中有一个编辑文本.当焦点放在编辑文本上时,布局上升.我尝试过

I have an edit text inside a bottom sheet fragment. when the focus come on the edit text the layout goes up . i tried

 android:windowSoftInputMode="adjustNothing"

它适用于父活动,但不适用于对话框片段.

its work for the parent activity but not for the dialog fragment.

这是我的入门课:

public class CustomBottomSheetDialogFragment extends BottomSheetDialogFragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.content_dialog_bottom_sheet, container, false);
        getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        return v;
    }
}

初始状态

键盘出现时

我希望布局始终保持在底部,键盘应位于布局上方.

i want the layout to always stay on the bottom the keyboard should come above the layout.

检查布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottomSheetLayout"
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@android:color/holo_blue_light"
android:padding="@dimen/activity_vertical_margin"
app:behavior_hideable="true"
app:behavior_peekHeight="60dp"
app:layout_behavior="@string/bottom_sheet_behavior">


<EditText
    android:id="@+id/edt"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="@android:color/white"
    android:padding="10dp" />

<TextView

    android:layout_width="wrap_content"
    android:layout_height="250dp"
    android:layout_below="@+id/edt" />

推荐答案

在您的Dialog Fragment中使用它.

getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

onCreateView内部是这样的.

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.dialog_fragment, container);

        //set to adjust screen height automatically, when soft keyboard appears on screen 
        getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);


        return rootView;
    }

我对您使用的layout进行了一些更改,以使其适用于当前的layout.

I have made some changes with what layout you are using make it apply in your current layout.

这里是layout.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:layout_gravity="bottom"
    android:background="@android:color/holo_blue_light"
    android:padding="10dp"
    app:behavior_hideable="true"
    app:behavior_peekHeight="60dp"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:isScrollContainer="false"
        android:scrollbars="vertical">

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

            <EditText
                android:id="@+id/edt"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="@android:color/white"
                android:padding="10dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="250dp"
                android:layout_below="@+id/edt" />

        </LinearLayout>


    </ScrollView>

</FrameLayout>

这里是Fragment.

public class TestFragment extends BottomSheetDialogFragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.test4, container, false);
        return v;
    }

您可以尝试 android:elevation ="50dp" 属性,用于底片上方的阴影,并尝试使用框架布局中的阴影.

You can try android:elevation="50dp" property for shadow above Bottom Sheet give a try with that in frame layout.

这篇关于键盘附带底片片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆