DKV*_*DKV 21 android bottom-sheet
我在底部片段中有一个编辑文本.当焦点出现在编辑文本上时,布局就会上升.我试过了
android:windowSoftInputMode="adjustNothing"
Run Code Online (Sandbox Code Playgroud)
它的工作是父活动,但不是对话框片段.
这是我的底层课程:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
初始状态
当键盘出现时
我希望布局始终保持在底部,键盘应位于布局上方.
检查布局
<?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" />
Run Code Online (Sandbox Code Playgroud)
Jay*_* RJ 20
在你的使用中
Dialog Fragment.
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Run Code Online (Sandbox Code Playgroud)
里面
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;
}
Run Code Online (Sandbox Code Playgroud)
编辑1:
我已经对
layout你正在使用的东西做了一些改变,使它适用于你当前的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>
Run Code Online (Sandbox Code Playgroud)
这是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;
}
Run Code Online (Sandbox Code Playgroud)
编辑2:
您可以尝试使用android:elevation ="50dp"属性为Bottom Sheet上方的阴影尝试使用框架布局中的阴影.
LOG*_*TAG 13
BottomSheetFragment的100%工作公式
在BottomSheetFragment中的onCreateDialog中使用它
KeyboardUtil(getActivity(), view);
Run Code Online (Sandbox Code Playgroud)
要么
用于片段使用
new KeyboardUtil(this, findViewById(R.id.fragment_container));
Run Code Online (Sandbox Code Playgroud)
通过使用此Util类
信用:Mikepenz
小智 5
似乎旧设计版本中存在错误.我遇到了同样的问题,但在我升级设计版本后,adjustnothing可以按预期工作.
在gradle中:
com.android.support:design:26.1.0
Run Code Online (Sandbox Code Playgroud)
在BottomSheetDialog中:
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15987 次 |
| 最近记录: |