Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Fullscreen dialog confirmation and dismissive actions

Fullscreen dialogs in material design should have the confirmation and dismissive actions on the actionbar/toolbar.

Material design fullscreen dialog

My question, how can i do this?

To show the dialog:

getFragmentManager().beginTransaction()
    .add(R.id.container, new MyDialogFragment())
    .addToBackStack(null).commit();

My dialog fragment:

public class MyDialogFragment extends DialogFragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         return inflater.inflate(R.layout.fragment_layout, container, false);
    }
}
like image 469
SunnySydeUp Avatar asked Nov 22 '14 06:11

SunnySydeUp


People also ask

How many types of dialogs are there in Android?

There are three kinds of lists available with the AlertDialog APIs: A traditional single-choice list. A persistent single-choice list (radio buttons) A persistent multiple-choice list (checkboxes)

What is full screen dialog?

fullscreenDialog: This property is used to notify the navigator whether the page is a new page or a full screen dialog. Setting this property to true will display a close icon ('X') on the appBar, while setting to false will display a back arrow icon('<-').

What is a dialog component?

Dialogs contain text and UI controls. They retain focus until dismissed or a required action has been taken. Use dialogs sparingly because they are interruptive. Some dialog types include: Alerts are urgent interruptions that inform about a situation and require acknowledgement.

How many action button can a dialog have?

Dialogs should contain a maximum of two actions.


1 Answers

Only two things need to be done:

  • Change the up icon
  • Add a menu to the fragment

Changing icon:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ((ActionBarActivity) getActivity()).getSupportActionBar().setHomeAsUpIndicator(android.R.drawable.ic_menu_close_clear_cancel);
}

Add Save menu:

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.save_menu, menu);
}

R.menu.save_menu:

<?xml version="1.0" encoding="utf-8"?>
<menu
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:android="http://schemas.android.com/apk/res/android">
   <item
       android:id="@+id/save
       app:showAsAction="always|withText"
       android:title="@string/save"/>
</menu>
like image 96
SunnySydeUp Avatar answered Oct 24 '22 20:10

SunnySydeUp