Android 底部的纸张碎片与键盘一起出现

Android 底部的纸张碎片与键盘一起出现,android,bottom-sheet,Android,Bottom Sheet,我有一个编辑文本内的底部页片段。当焦点出现在编辑文本上时,布局向上。我试过了 android:windowSoftInputMode="adjustNothing" 它适用于父活动,但不适用于对话框片段 这是我的最底层课程: public class CustomBottomSheetDialogFragment extends BottomSheetDialogFragment { @Override public View onCreateView(LayoutInfla

我有一个编辑文本内的底部页片段。当焦点出现在编辑文本上时,布局向上。我试过了

 android:windowSoftInputMode="adjustNothing"
它适用于父活动,但不适用于对话框片段

这是我的最底层课程:

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;
    }
}
初始状态

当键盘出现时

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

检查布局

<?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" />

对话框片段中使用此选项

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;
    }
内部
onCreateView
如下所示

编辑1:

我对您正在使用的
布局
做了一些更改,使其应用于当前的
布局

<?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>
这里是
布局

<?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>
编辑2:

您可以尝试使用android:elevation=“50dp”属性设置底部图纸上方的阴影,并尝试使用框架布局中的阴影


在清单中的活动声明中,放置以下代码行:

android:windowSoftInputMode="stateHidden"
android:windowTranslucentNavigation="true"
android:windowTranslucentStatus="true" 

从中替换您的旗帜

adjustNothing

adjustPan


选中

获取对话框的装饰视图,并将底部填充设置为高度
0
或您的对话框高度

getDialog.getWindow.getDecorView.setpadding(0,0,0,0);

100%的工作公式,适用于底部碎片

在BottomSheetFragment的onCreateDialog中使用此选项

KeyboardUtil(getActivity(), view);

供碎片使用

new KeyboardUtil(this, findViewById(R.id.fragment_container));
通过使用这个Util类


信贷:Mikepenz似乎在旧设计版本中存在缺陷。 我遇到了同样的问题,但是在我升级了设计版本之后,没有任何东西可以像预期的那样工作

在格拉德尔:

com.android.support:design:26.1.0
在对话框中:

getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);

我也遇到过同样的情况,我用SearchView代替EditText。当BottomSheetDialog进入隐藏状态时,键盘没有隐藏

只需将其称为search_channel_template.clearFocus()

我将分享我用来隐藏键盘的代码

search_channel_template = (SearchView) bottomSheetDialog.findViewById(R.id.search_channel_template);

txtVw_template_headerBS_down_id.setOnClickListener(new OnSingleClickListener() {
            @Override
            public void onSingleClick(View v) {
                search_channel_template.clearFocus();
                bottomSheetDialog.getBehavior().setState(BottomSheetBehaviorv2.STATE_HIDDEN);
            }
        });

您是否以编程方式尝试过?发布屏幕截图以获得更多的想法。你能给我你的底片片段的代码吗?我想和你键盘上面的底片一样,就像你在上面实现的一样@DKV@VV张贴您的对话片段代码,并用屏幕截图再现准确的问题。向我展示您的
onCreateDialog
方法。@VV发布您的代码和屏幕截图,以获得确切的问题。没有这一点,没有人可以指导您解决此问题。请检查更新。请告诉我您想了解更多详细信息。@VV您能告诉我您的
布局
内容对话框\u底部\u表中包含的内容吗。@jaydroider:请检查布局启用和禁用方法如何,您在哪里使用它们?这对我有帮助,我的同事推荐了您的答案。这对我来说很有用,但我只需要替换类//get screen height中的这两行,然后用r int height=contentView.getHeight()中的可用区域计算差值;int diff=(int)(高度-r.bottom+r.top+decorView.getContext().getResources().getdimen(r.dimen.16dp));
search_channel_template = (SearchView) bottomSheetDialog.findViewById(R.id.search_channel_template);

txtVw_template_headerBS_down_id.setOnClickListener(new OnSingleClickListener() {
            @Override
            public void onSingleClick(View v) {
                search_channel_template.clearFocus();
                bottomSheetDialog.getBehavior().setState(BottomSheetBehaviorv2.STATE_HIDDEN);
            }
        });