Implementing proper back navigation and home button handling using Toolbar in Android

前端 未结 6 1825
粉色の甜心
粉色の甜心 2021-01-30 23:31

I am using a single activity and multiple fragments(screenshot attached) within the same activity to provide a seamless navigation. But after implementing the latest toolbar and

6条回答
  •  不思量自难忘°
    2021-01-31 00:26

    "Page title - Changing the page titles whenever a fragment in pushed and popped"

    When you remove a fragment, there is the method isRemoving(). It helps to change title back.

    @Override
    public void onStop() {
        super.onStop();
        if (isRemoving()) {
            // Change your title here
        }
    }
    

    "functionality to Menu and Back nav"

    Suggestion: we have to rely on the default android navigation system. If we use addToBackStack() for our fragments, in theory we don't have to override onBackPressed() at all.

    1. "App does not redefine the expected function of a system icon (such as the Back button)."
    2. "App supports standard system Back button navigation and does not make use of any custom, on-screen "Back button" prompts."

    Core App Quality: https://developer.android.com/distribute/essentials/quality/core.html

    "Managing the Hamburger/Back button at left top"

    I suggest to use activity instead of 'MainActivityDetailFragment' to avoid complication.

提交回复
热议问题