Coder Social home page Coder Social logo

fragmentdrawer's Introduction

FragmentDrawer

Sample Android Studio App (Java) with 1 Activity and a left side sliding drawer with a menu of items that load and display different Fragments. There is also an AppBarLayout item and a FloatingActionButton that load and display Fragments.

It uses:

  • NavigationView (design.widget.NavigationView)
  • DrawerLayout (widget.DrawerLayout)
  • AppBarLayout (design.widget.AppBarLayout)
  • Toolbar (widget.Toolbar)
  • Foating Action Button (widget.FloatingActionButton)

Here are the screenshots from the app:

||||| | | | ||

(the last image, "Button", is the fragment that gets loaded when the blue "?" button is pressed)

Overview

I have found several examples of using a "Drawer" sliding menu and a few other examples of how to load a fragment from an activity. But I did not find an example of how to do both in the same app. There are some very cool libraries available to do this but they may be overkill for the simple use cases. I wrote this sample app as a learning tool and wish to share it with others.

NOTE: Something like this could (should?) have been part of Android Studio "Start a New Android Studio Project" or "Import an Android Code Sample".

Prerequisites

You will need the following to build and run this app:

  • Android Studio 3.0+
  • Copy of this repository (click "Clone or Download" on main page) GitHub repo

Build and Deployment

I built and tested this on a Google Pixel XL. I did not even try any simulators.

Code Highlights (the Secret Sauce...)

  • loadFragment() function in Activity.java
  • content.xml (included by activity.xml) has a Frame with id="content"
  • DrawerLayout calls onNavigationItemSelected() function in Activity.java when menu item is tapped
  • onNavigationItemSelected() calls loadFragment() function and loads selected Fragment into the "content" Frame
  • AppBarLayout item and FloatingActionButton use same loadFragment() function to load their own fragments

Author

License

This project is licensed under the MIT License: https://opensource.org/licenses/MIT

fragmentdrawer's People

Contributors

byteslinger avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.