Navigation Drawer On The Top Of Actionbar / Statusbar Like Android 5.0 Without Using Appcompact / Toolbar
Solution 1:
In a regular Activity
, the ActionBar
is part of an overlay View
that is the only direct child of the Window
's DecorView
. You can remove this child from the DecorView
, inflate the activity_main
main layout into the DecorView
, and then add the overlay View
to the DrawerLayout
's FrameLayout
, effectively putting the drawer on top of everything.
In order to avoid making changes to the BaseLogeableActivity
class, we'll need to change the ID of the DrawerLayout
's FrameLayout
, and ensure a Resource ID of container
exists to assign to the dynamically created FrameLayout
that will hold the Fragment
s.
Create the Resource ID of container
, if necessary:
<item type="id" name="container" />
Change the ID of the main layout's FrameLayout
:
<FrameLayout
android:id="@+id/overlay_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
The cleanest way to add the View
juggling code is probably to just override MainActivity
's setContentView()
method, like so:
@OverridepublicvoidsetContentView(int layoutResID) {
ViewGroupdecorView= (ViewGroup) getWindow().getDecorView();
ViewoverlayView= decorView.getChildAt(0);
decorView.removeView(overlayView);
getLayoutInflater().inflate(layoutResID, decorView, true);
FrameLayoutoverlayContainer= (FrameLayout) findViewById(R.id.overlay_container);
overlayContainer.addView(overlayView);
FrameLayoutcontainer=newFrameLayout(this);
container.setId(R.id.container);
ViewGroupcontent= (ViewGroup) overlayView.findViewById(android.R.id.content);
content.addView(container);
}
And finally, if you want your Activity
to cover the Status Bar, add the following attribute setting to its theme:
<item name="android:windowFullscreen">true</item>
Or, since you can't change the theme, call the following before the setContentView()
call:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Post a Comment for "Navigation Drawer On The Top Of Actionbar / Statusbar Like Android 5.0 Without Using Appcompact / Toolbar"