0

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:

enter image description here

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!

Bao HQ
  • 1,145
  • 7
  • 18
  • 1
    Just a quick idea, perhaps the fragment is in front of the button, so that the touchevent is handled by the fragment and not the button in the main layout, because your fragment takes up all the space with the match parent attribute. – Malte Sep 17 '15 at 14:41
  • I think that there may be the ways to make events to layout under dialog fragment. But i dont find out yet. So I thank to experts here. – Bao HQ Sep 17 '15 at 18:07
  • Why Dont you put the mainlayout button on the bottom and the fragment above? – Malte Sep 18 '15 at 20:46

1 Answers1

0

Instead of using android:layout_height="match_parent" from both main and fragment layout try using wrap_content or test with fixed dp

justLearning
  • 299
  • 2
  • 7
  • Thanks for your idea, but i want that dialog layout is match parent. Are there any ways that can resolve it? – Bao HQ Sep 17 '15 at 18:00