Browse Category

Fragments

Navigation Component: How to move the Drawer under the ToolBar?

Navigation Drawer Activity Template

Recently I was struggling with Navigation Component and succeded in solving some of its issues. I am happy to share with you the solutions I’ve found.

GitHub Repo: https://github.com/Pulimet/NavigationComponentSample

Create a project and select the template “Navigation Drawer Activity”. You will get the ToolBar, Drawer and navigation stuff for free as shown in the screenshot.

Now, let’s assume that we got a request to move the drawer under the ToolBar. We need to modify activity_main.xml for that.

Create vertical LinearLayout and make it wrapping DrawerLayout

Open app_bar_main.xml copy AppBarLayout and paste it as a first item in the previously created LinearLayout.

Also from the app_bar_main.xml get the include (content_main) and put it as a first child of DrawerLayout instead of existing include of app_bar_main.xml.

Delete app_bar_main.xml file

In v21\styles.xml – remove the line that makes status bar transparent.

Keep Reading

Fragment transition with shared element supporting API 14+ example/tutorial

Now (27.0.0 support library) fragment can use support library versions of Transition for fragment transitions, including shared-element transitions.
https://developer.android.com/topic/libraries/support-library/revisions.html#27-0-0

Support android.transition classes provide transition API back to android API level 14.
https://developer.android.com/reference/android/support/transition/package-summary.html

Inspired by: Fragment Tricks (Google I/O ’17).

So let’s start with the build.gradle (support library 27.0.0+) :

implementation 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support:design:27.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'

Keep Reading

Useful and forgettable Fragment methods

  • isAdded() – Return true if the fragment is currently added to its activity.
  • isHidden() – Return true if the fragment has been hidden.
  • isVisible() – Return true if the fragment is currently visible to the user.