I have a problem with handling dialog fragment. I thank to you!
My code as below:
Main activity:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
UnderlayerDialogFragment underlayerDialogFragment = new UnderlayerDialogFragment();
underlayerDialogFragment.show(getFragmentManager(), "");
}
}
DialogFragment:
public class UnderlayerDialogFragment extends DialogFragment{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_fragment_underlayer, container, false);
return view;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
}
main layout:
<LinearLayout
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"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="Button on main layout"/>
</LinearLayout>
dialog fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_material_dark"
android:alpha="0.5">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Button on DialogFragment layout"/>
</RelativeLayout>
The following is my screen after deploying:
I want:
I can touch on the buttons "Button on main layout" and "Button on Dialog Fragment layout"
the problem:
I can touch on the button "Button on Dialog Fragment layout", but I can not touch on the button "Button on main layout".
Please help me!!!
Thank you!