Android 安卓对话框没有';当软键盘关闭时,不要回到底部
我制作了一个自定义对话框,其中的EditText从底部显示,在软键盘打开时向上推:Android 安卓对话框没有';当软键盘关闭时,不要回到底部,android,dialog,Android,Dialog,我制作了一个自定义对话框,其中的EditText从底部显示,在软键盘打开时向上推: final Dialog priceFilterDialog = new Dialog(getActivity(), R.style.DialogFilter); View priceFilterView = inflater2.inflate(R.layout.view_price_filter, null); priceFilterDialog.setContentView(pric
final Dialog priceFilterDialog = new Dialog(getActivity(), R.style.DialogFilter);
View priceFilterView = inflater2.inflate(R.layout.view_price_filter, null);
priceFilterDialog.setContentView(priceFilterView); // your custom view.
priceFilterDialog.setCancelable(true);
priceFilterDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
priceFilterDialog.getWindow().setGravity(Gravity.BOTTOM);
priceFilterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
问题是,当用户关闭键盘时,对话框不会返回底部,而是停留在屏幕的中间,由键盘向上推
我的R.layout.视图\u价格\u过滤器
:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/cl_filter"
android:focusable="true"
android:layout_gravity="bottom"
android:focusableInTouchMode="true">
<!-- Dialog content here -->
</android.support.constraint.ConstraintLayout>
这就是片段内部发生的情况:
public class SearchFragment extends Fragment {
private OnFragmentInteractionListener mListener;
public SearchFragment() {
}
public static SearchFragment newInstance() {
SearchFragment fragment = new SearchFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View view = inflater.inflate(R.layout.fragment_search, container, false);
// Other unrelated code
LayoutInflater inflater2 = this.getLayoutInflater();
// Price Filter
final Dialog priceFilterDialog = new Dialog(getActivity(), R.style.DialogFilter);
View priceFilterView = inflater2.inflate(R.layout.view_price_filter, null);
priceFilterDialog.setContentView(priceFilterView); // your custom view.
priceFilterDialog.setCancelable(true);
priceFilterDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
priceFilterDialog.getWindow().setGravity(Gravity.BOTTOM);
priceFilterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
// Other unrelated code
return view;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
void onFragmentInteraction(Uri uri);
}
}
您可以从上面的代码(在clean/pure中)应用程序正常工作(对话框正在关闭):
您可以从上面(在clean/pure中)编写代码,应用程序可以正常工作(对话框正在关闭):
您可以直接从清单中将其设置为“活动”选项卡的属性,而不是将其设置为dialogwidow!我尝试在清单活动属性上使用android:WindowsOfInputMode=“adjustPan | adjustResize”,但它仍然没有返回到底部。您可以直接从清单将其设置为活动选项卡的属性,而不是将其设置为对话框窗口!我尝试在清单活动属性上使用android:WindowsOfInputMode=“adjustPan | adjustResize”,但它仍然没有返回底部。我尝试了,但仍然没有返回底部。这在片段中发生的事实会改变什么吗?如果你能在我上传的代码中找到问题,这将对我非常有帮助@Gicminos你必须把你的整个应用程序上传到某个地方。我试过了,但还是没有回到底部。这在片段中发生的事实会改变什么吗?如果你能在我上传的代码中找到问题,这将对我非常有帮助@Gicminos你必须将整个应用程序上传到某个地方。
public class SearchFragment extends Fragment {
private OnFragmentInteractionListener mListener;
public SearchFragment() {
}
public static SearchFragment newInstance() {
SearchFragment fragment = new SearchFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View view = inflater.inflate(R.layout.fragment_search, container, false);
// Other unrelated code
LayoutInflater inflater2 = this.getLayoutInflater();
// Price Filter
final Dialog priceFilterDialog = new Dialog(getActivity(), R.style.DialogFilter);
View priceFilterView = inflater2.inflate(R.layout.view_price_filter, null);
priceFilterDialog.setContentView(priceFilterView); // your custom view.
priceFilterDialog.setCancelable(true);
priceFilterDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
priceFilterDialog.getWindow().setGravity(Gravity.BOTTOM);
priceFilterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
// Other unrelated code
return view;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
void onFragmentInteraction(Uri uri);
}
}