SlidingRootNav
DrawerLayout-like ViewGroup, where a "drawer" is hidden under the content view, which can be shifted to make the drawer visible.
Top Related Projects
toast-like alert pattern for Android inspired by the Google Material Design Spec
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
swipe display drawer with flowing & bouncing effects.
Material Design Search Bar for Android
Side menu with some categories to choose.
Android Floating Action Button based on Material Design specification
Quick Overview
SlidingRootNav is an Android library that provides a sliding root navigation drawer. It offers a customizable drawer that can be pulled out from the edge of the screen, similar to the standard Android navigation drawer, but with more flexibility in terms of content and animation.
Pros
- Highly customizable with various animation options
- Supports both left and right drawer positions
- Easy integration with existing Android projects
- Smooth performance and fluid animations
Cons
- Limited documentation and examples
- May require additional effort to implement complex layouts
- Not actively maintained (last update was in 2018)
- Potential compatibility issues with newer Android versions
Code Examples
- Basic setup of SlidingRootNav:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.inject()
setContentView(R.layout.activity_main)
}
- Customizing the drawer's appearance and behavior:
SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.withDragDistance(140) // Horizontal translation of a view
.withRootViewScale(0.7f) // Content view's scale will be interpolated between 1f and 0.7f
.withRootViewElevation(10) // Content view's elevation will be interpolated between 0 and 10dp
.withRootViewYTranslation(4) // Content view's translationY will be interpolated between 0 and 4dp
.inject()
- Opening and closing the drawer programmatically:
val slidingRootNav: SlidingRootNav = // ... obtain reference to SlidingRootNav
// Open the drawer
slidingRootNav.openMenu()
// Close the drawer
slidingRootNav.closeMenu()
// Check if the drawer is currently open
val isMenuOpen = slidingRootNav.isMenuOpened
Getting Started
To use SlidingRootNav in your Android project:
- Add the JitPack repository to your project's
build.gradle
:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency to your app's
build.gradle
:
dependencies {
implementation 'com.github.yarolegovich:SlidingRootNav:1.1.0'
}
- Implement the sliding root navigation in your activity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.inject()
}
Competitor Comparisons
toast-like alert pattern for Android inspired by the Google Material Design Spec
Pros of SnackBar
- Simpler implementation focused on displaying short messages
- Lightweight and easy to integrate into existing projects
- Customizable appearance and duration of messages
Cons of SnackBar
- Limited functionality compared to a full navigation drawer
- Less suitable for complex navigation structures
- May require additional components for a complete navigation solution
Code Comparison
SnackBar usage:
Snackbar.with(getApplicationContext())
.text("Hello World")
.duration(Snackbar.SnackbarDuration.LENGTH_SHORT)
.show(this);
SlidingRootNav usage:
new SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.inject();
While both libraries serve different purposes, SnackBar focuses on displaying temporary messages, whereas SlidingRootNav provides a complete sliding navigation drawer solution. SnackBar is more suitable for quick notifications or feedback, while SlidingRootNav is better for implementing complex navigation structures in Android applications.
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
Pros of MaterialDrawer
- More comprehensive and feature-rich, offering a wide range of customization options
- Extensive documentation and active community support
- Seamless integration with other Material Design components
Cons of MaterialDrawer
- Larger library size, potentially increasing app size
- Steeper learning curve due to its extensive feature set
- May be overkill for simple navigation drawer requirements
Code Comparison
SlidingRootNav:
SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.inject()
MaterialDrawer:
DrawerBuilder()
.withActivity(this)
.withToolbar(toolbar)
.addDrawerItems(
PrimaryDrawerItem().withName("Home"),
SecondaryDrawerItem().withName("Settings")
)
.build()
Summary
MaterialDrawer offers a more comprehensive solution with extensive customization options and better integration with Material Design components. However, it comes at the cost of a larger library size and potentially more complex implementation. SlidingRootNav, on the other hand, provides a simpler and more lightweight approach to creating sliding navigation drawers, which may be preferable for projects with basic navigation requirements or those prioritizing a smaller app size.
swipe display drawer with flowing & bouncing effects.
Pros of FlowingDrawer
- Offers a unique, fluid animation for the drawer opening and closing
- Provides a more visually appealing and modern design
- Allows for customization of the drawer's shape and flow
Cons of FlowingDrawer
- Less actively maintained (last update was in 2017)
- Fewer configuration options compared to SlidingRootNav
- May have compatibility issues with newer Android versions
Code Comparison
FlowingDrawer:
mDrawer = (FlowingDrawer) findViewById(R.id.drawerlayout);
mDrawer.setTouchMode(ElasticDrawer.TOUCH_MODE_BEZEL);
mDrawer.setOnDrawerStateChangeListener(new ElasticDrawer.OnDrawerStateChangeListener() {
@Override
public void onDrawerStateChange(int oldState, int newState) {
// Handle state change
}
});
SlidingRootNav:
new SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.withDragDistance(140)
.withRootViewScale(0.7f)
.withRootViewElevation(10)
.withToolbarMenuToggle(toolbar)
.inject();
The code comparison shows that SlidingRootNav offers more configuration options in its builder pattern, while FlowingDrawer focuses on touch mode and state change listeners.
Material Design Search Bar for Android
Pros of MaterialSearchBar
- Focused on search functionality with built-in suggestions and customizable UI
- Lightweight and easy to integrate into existing projects
- Supports voice search and custom animations
Cons of MaterialSearchBar
- Limited to search bar functionality, not a full navigation solution
- May require additional libraries for more complex navigation patterns
- Less actively maintained compared to SlidingRootNav
Code Comparison
MaterialSearchBar:
MaterialSearchBar searchBar = findViewById(R.id.searchBar);
searchBar.setHint("Search");
searchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
@Override
public void onSearchStateChanged(boolean enabled) {
// Handle search state change
}
});
SlidingRootNav:
new SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.withDragDistance(140)
.withRootViewScale(0.7f)
.withRootViewElevation(10)
.inject();
Summary
MaterialSearchBar is a specialized library for implementing search functionality with a material design aesthetic. It offers a streamlined approach to adding search capabilities to an app, including suggestions and voice search. However, it's limited in scope compared to SlidingRootNav, which provides a more comprehensive navigation solution. SlidingRootNav offers greater flexibility for creating custom navigation drawers and sliding menus, making it more suitable for apps requiring complex navigation patterns. The choice between the two depends on the specific needs of the project, with MaterialSearchBar being ideal for search-centric applications and SlidingRootNav better suited for apps requiring versatile navigation options.
Side menu with some categories to choose.
Pros of Side-Menu.Android
- Offers a visually appealing and animated side menu with customizable transitions
- Provides a more modern and stylish design out of the box
- Includes additional UI elements like circular reveal effects
Cons of Side-Menu.Android
- Less flexible in terms of customization compared to SlidingRootNav
- May require more effort to integrate with existing app layouts
- Limited to a specific design style, which might not fit all app aesthetics
Code Comparison
Side-Menu.Android:
ResideMenu resideMenu = new ResideMenu(this);
resideMenu.setBackground(R.drawable.menu_background);
resideMenu.attachToActivity(this);
resideMenu.addMenuItem(menuItem, ResideMenu.DIRECTION_LEFT);
SlidingRootNav:
new SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.withDragDistance(140)
.withRootViewScale(0.7f)
.inject();
SlidingRootNav offers a more flexible and customizable approach, allowing developers to easily integrate it with existing layouts. Side-Menu.Android, on the other hand, provides a more opinionated and visually striking design out of the box, but with less flexibility for customization.
Both libraries offer easy-to-use APIs, but SlidingRootNav's approach may be more suitable for developers who need fine-grained control over the navigation drawer's behavior and appearance. Side-Menu.Android is ideal for those looking for a quick implementation of a visually appealing side menu with minimal customization requirements.
Android Floating Action Button based on Material Design specification
Pros of FloatingActionButton
- Focused on a specific UI element (FAB), making it easier to implement and customize
- Provides various animation options for the FAB, enhancing user experience
- Lightweight and less complex, suitable for projects that only need FAB functionality
Cons of FloatingActionButton
- Limited to FAB implementation, lacking the comprehensive navigation features of SlidingRootNav
- May require additional libraries or custom code for more complex navigation patterns
- Less flexibility in terms of overall app structure and navigation design
Code Comparison
SlidingRootNav:
new SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.inject();
FloatingActionButton:
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Handle click event
}
});
The code snippets demonstrate the difference in focus and implementation. SlidingRootNav provides a more comprehensive navigation setup, while FloatingActionButton is specifically for adding and customizing a FAB in the layout.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
SlidingRootNav
The library is a DrawerLayout-like ViewGroup, where a "drawer" is hidden under the content view, which can be shifted to make the drawer visible. It doesn't provide you with a drawer builder.
Gradle
Add this into your dependencies block.
compile 'com.yarolegovich:sliding-root-nav:1.1.1'
Sample
Please see the sample app for a library usage example.
Wiki
Usage:
- Create your content_view.xml (example) or construct a
View
programatically. - Set the content view (for example, using
setContentView
in your activity). - Create your menu.xml (example) or construct a
View
programatically. - Now you need to inject the menu in your
onCreate
. You can specify transformations of a content view or use the default ones.
new SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.inject();
API
Transformations
You can specify root transformations using SlidingRootNavBuilder
.
new SlidingRootNavBuilder(this)
.withDragDistance(140) //Horizontal translation of a view. Default == 180dp
.withRootViewScale(0.7f) //Content view's scale will be interpolated between 1f and 0.7f. Default == 0.65f;
.withRootViewElevation(10) //Content view's elevation will be interpolated between 0 and 10dp. Default == 8.
.withRootViewYTranslation(4) //Content view's translationY will be interpolated between 0 and 4. Default == 0
.addRootTransformation(customTransformation)
.inject();
customTransformation
in the above example is a user-created class that implements RootTransformation
interface. For an example, refer to the default transformations.
Menu behavior
new SlidingRootNavBuilder(this)
.withMenuOpened(true) //Initial menu opened/closed state. Default == false
.withMenuLocked(false) //If true, a user can't open or close the menu. Default == false.
.withGravity(SlideGravity.LEFT) //If LEFT you can swipe a menu from left to right, if RIGHT - the direction is opposite.
.withSavedState(savedInstanceState) //If you call the method, layout will restore its opened/closed state
.withContentClickableWhenMenuOpened(isClickable) //Pretty self-descriptive. Builder Default == true
Controling the layout
A call to inject()
returns you an interface for controlling the layout.
public interface SlidingRootNav {
boolean isMenuClosed();
boolean isMenuOpened();
boolean isMenuLocked();
void closeMenu();
void closeMenu(boolean animated);
void openMenu();
void openMenu(boolean animated);
void setMenuLocked(boolean locked);
SlidingRootNavLayout getLayout(); //If for some reason you need to work directly with layout - you can
}
Callbacks
- Drag progress:
builder.addDragListener(listener);
public interface DragListener {
void onDrag(float progress); //Float between 0 and 1, where 1 is a fully visible menu
}
- Drag state changes:
builder.addDragStateListener(listener);
public interface DragStateListener {
void onDragStart();
void onDragEnd(boolean isMenuOpened);
}
- Compatibility with
DrawerLayout.DrawerListener
:
DrawerListenerAdapter adapter = new DrawerListenerAdapter(yourDrawerListener, viewToPassAsDrawer);
builder.addDragListener(listenerAdapter).addDragStateListener(listenerAdapter);
Special thanks
Thanks to Tayisiya Yurkiv for a beautiful GIF.
License
Copyright 2017 Yaroslav Shevchuk
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Top Related Projects
toast-like alert pattern for Android inspired by the Google Material Design Spec
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
swipe display drawer with flowing & bouncing effects.
Material Design Search Bar for Android
Side menu with some categories to choose.
Android Floating Action Button based on Material Design specification
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot