【发布时间】:2016-03-22 09:15:31
【问题描述】:
我有全屏片段对话框。在显示时,背景对象可以是可点击的或与用户交互。如何避免这种情况?
这是我如何显示对话框的一段代码:
MainActivity.java
FullScreenFrDialog fr = new FullScreenFrDialog();
FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
tr.add(android.R.id.content, fr, FR_TAG).commit();
FullScreenFrDialog.java
public class FullScreenFrDialog extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog, container, false);
return view;
}
}
dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CCFFFFFF" >
<ImageView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</FrameLayout>
main_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
此按钮可点击,同时显示对话框。
提前致谢。
【问题讨论】:
-
只需在
onCreateView(...)中添加setCancelable(false); -
@MD 我试过这个,但它是可点击的。
标签: java android android-dialogfragment dialogfragment