Step 1:
Add Dependencies app/Gradle/build.gradle −
dependencies {
implementation libs.appcompat
implementation libs.material
implementation libs.activity
implementation libs.constraintlayout
testImplementation libs.junit
androidTestImplementation libs.ext.junit
androidTestImplementation libs.espresso.core
implementation 'com.github.learnoset:material:3.38' //add Library
}
Step 2:
Add Library app/Gradle/settings.gradle −
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {url 'https://jitpack.io' } //add maven
}
}
Step 3:
File open res/layout/activity_main.xml file −
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/headind"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/menuOpen"
android:layout_width="35dp"
android:layout_height="?attr/actionBarSize"
android:src="@drawable/men_icon" />
<TextView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center"
android:text="@string/app_name"
android:textSize="23sp" />
</LinearLayout>
<FrameLayout
android:id="@+id/frameContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/headind" />
</RelativeLayout>
<com.learnoset.material.ui.learnosetnavigationbar.LearnosetNavigationBar
android:id="@+id/navigationBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start" />
</androidx.drawerlayout.widget.DrawerLayout>
Step 4:
File open com.microappvalley.newtestproject/MainActivity.java file −
package com.tutorialb.customnavigationdrawer;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.GravityCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import com.learnoset.material.ui.learnosetnavigationbar.CustomNavTheme;
import com.learnoset.material.ui.learnosetnavigationbar.LearnosetNavItem;
import com.learnoset.material.ui.learnosetnavigationbar.LearnosetNavigationBar;
public class MainActivity extends AppCompatActivity {
ImageView menuOpen;
LearnosetNavigationBar learnosetNavigationBar;
DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
learnosetNavigationBar = findViewById(R.id.navigationBar);
drawerLayout = findViewById(R.id.drawerLayout);
menuOpen = findViewById(R.id.menuOpen);
//click button to open drawer
learnosetNavigationBar.setDrawerLayout(drawerLayout, LearnosetNavigationBar.DrawerGravity.LEFT);
menuOpen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawerLayout.openDrawer(GravityCompat.START);
}
});
//add menu items and icon
LearnosetNavItem customItem1 = new LearnosetNavItem("Home", R.drawable.baseline_home_24);
LearnosetNavItem customItem2 = new LearnosetNavItem("Share", R.drawable.baseline_share_24);
LearnosetNavItem customItem3 = new LearnosetNavItem("Rate us", R.drawable.baseline_star_rate_24);
LearnosetNavItem customItem4 = new LearnosetNavItem("Privacy", R.drawable.baseline_privacy_tip_24);
learnosetNavigationBar.addNavItem(customItem1);
learnosetNavigationBar.addNavItem(customItem2);
learnosetNavigationBar.addNavItem(customItem3);
learnosetNavigationBar.addNavItem(customItem4);
//header name and image
learnosetNavigationBar.setHeaderData("Jony", R.drawable.baseline_person_24);
//change theme, icon, text etc. color
learnosetNavigationBar.setTheme(LearnosetNavigationBar.NavThemes.LIGHT);
learnosetNavigationBar.setIconsColor(LearnosetNavigationBar.NavColors.RED);
learnosetNavigationBar.setSelectedItemBackground(LearnosetNavigationBar.NavColors.ORANGE);
CustomNavTheme changeTeame = new CustomNavTheme();
changeTeame.setNavigationBackground(Color.BLACK);
changeTeame.setTextColor(Color.WHITE);
learnosetNavigationBar.setTheme(changeTeame);
learnosetNavigationBar.enableLogOutBtn(false);
}
}
Open Device Manager, run the emulator, and then run the application. Next, check the working output and check the output you declared in your code.
Output: Home Page
Output: Navigation Drawer