# MoonyNavBar

[Permalink](https://github.com/doctor-blue/moony_nav_bar_android/blob/e6f3c75af0e8bb410ad5b7c4736afad301e651df/README.md)

## MoonyNavBar

[![](https://camo.githubusercontent.com/5aea0ae08e32f70a59b496ab2ef0848367e9520c9437ca54a5a036264a7f30fa/68747470733a2f2f6a69747061636b2e696f2f762f646f63746f722d626c75652f6d6f6f6e795f6e61765f6261725f616e64726f69642e737667)](https://jitpack.io/#doctor-blue/moony_nav_bar_android) [![API](https://camo.githubusercontent.com/0d5e6876261d372564c364129cad39375617ba6cf33a3a558d79f97a761e78f4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4150492d31362532422d627269676874677265656e2e7376673f7374796c653d666c6174)](https://android-arsenal.com/api?level=16)

### Flutter version [here](https://github.com/doctor-blue/moony_nav_bar_flutter)

### Donate

[![Buy Me A Coffee](https://camo.githubusercontent.com/3ba8042b343d12b84b85d2e6563376af4150f9cd09e72428349c1656083c8b5a/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f64656661756c742d6f72616e67652e706e67)](https://www.buymeacoffee.com/doctorblue) [![paypal](https://camo.githubusercontent.com/361950b331ef676b7eec436a4dbe5a7ce47211a6623dcc889b1f5b7b611b27df/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e61746543435f4c472e676966)](https://www.paypal.me/doctorblue00)

### GIF

[![](https://raw.githubusercontent.com/doctor-blue/moony_nav_bar_android/master/images/demo2.gif)](https://raw.githubusercontent.com/doctor-blue/moony_nav_bar_android/master/images/demo2.gif)[![](https://raw.githubusercontent.com/doctor-blue/moony_nav_bar_android/master/images/demo1.gif)](https://raw.githubusercontent.com/doctor-blue/moony_nav_bar_android/master/images/demo1.gif)

* Create menu.xml under your res/menu/ folder

&#x20;">

```markup
xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/first_fragment"
        android:title="@string/home"
        android:icon="@drawable/ic_outline_home_24"/>

    <item
        android:id="@+id/second_fragment"
        android:title="@string/notification"
        android:icon="@drawable/ic_outline_notifications_24"
        />

    <item
        android:id="@+id/third_fragment"
        android:title="@string/folder"
        android:icon="@drawable/ic_outline_folder_24"/>
    <item
        android:id="@+id/fourthFragment"
        android:title="@string/user"
        android:icon="@drawable/ic_outline_account_24"/>

menu>
```

* Add view into your layout file

### Sample:

&#x20;">

```markup
 <com.devcomentry.library.MoonyNavBar
        android:id="@+id/moony_nav_bar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_menu"
        />
```

### Customization

&#x20;">

```markup
   <com.devcomentry.library.MoonyNavBar
        android:id="@+id/moony_nav_bar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_menu"
        app:indicatorColor=""
        app:iconTintActive=""
        app:iconTint=""
        app:iconSize=""
        app:indicatorType=""
        app:indicatorPosition=""
        app:backgroundColor=""
        app:duration=""
        />
```

* Use MoonyNavBar callbacks in your activity

```kotlin
binding.moonyNavBar.onItemSelected = {
    if(it==R.id.your_menu_id){
      //your code
    }
}

binding.moonyNavBar.onItemReselected = {
     if(it==R.id.your_menu_id){
      //your code
    }
}
```

OR

```kotlin
  binding.moonyNavBar.onItemSelectedListener = object : OnItemSelectedListener {
    override fun onItemSelect(id: Int) {
        if (it == R.id.your_menu_id) {
            //your code
        }
    }
}

 binding.moonyNavBar.onItemReselectedListener = object : OnItemReselectedListener {
    override fun onItemReselect(id: Int) {
        if (it == R.id.your_menu_id) {
            //your code
        }
    }

}
```

### If you don't like callback, you can use [Navigation Components](https://developer.android.com/guide/navigation/).

* Setup Navigation Component i.e. Add dependenccy to your project, create a Navigation Graph etc.
* For each Fragment in your Navigation Graph, ensure that the Fragment's `id` is the same as the MenuItems in your Menu i.e res/menu/ folder

&#x20;">

```markup
xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/first_fragment"
        android:title="@string/home"
        android:icon="@drawable/ic_outline_home_24"/>

    <item
        android:id="@+id/second_fragment"
        android:title="@string/notification"
        android:icon="@drawable/ic_outline_notifications_24"
        />

    <item
        android:id="@+id/third_fragment"
        android:title="@string/folder"
        android:icon="@drawable/ic_outline_folder_24"/>
    <item
        android:id="@+id/fourth_fragment"
        android:title="@string/user"
        android:icon="@drawable/ic_outline_account_24"/>

menu>
```

* Navigation Graph i.e res/navigation/ folder

&#x20;">

```markup
xml version="1.0" encoding="utf-8"?>
<navigation 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/nav_graph"
    app:startDestination="@id/first_fragment"
    tools:ignore="UnusedNavigation">

    <fragment
        android:id="@+id/first_fragment"
        android:name="com.devcomentry.moonynavbar.FirstFragment"
        android:label="fragment_first"
        tools:layout="@layout/fragment_first" >
        <action
            android:id="@+id/action_firstFragment_to_secondFragment"
            app:destination="@id/second_fragment" />
    fragment>
    <fragment
        android:id="@+id/second_fragment"
        android:name="com.devcomentry.moonynavbar.SecondFragment"
        android:label="fragment_second"
        tools:layout="@layout/fragment_second" >
        <action
            android:id="@+id/action_secondFragment_to_thirdFragment"
            app:destination="@id/third_fragment" />
    fragment>
    <fragment
        android:id="@+id/third_fragment"
        android:name="com.devcomentry.moonynavbar.ThirdFragment"
        android:label="fragment_third"
        tools:layout="@layout/fragment_third" >
        <action
            android:id="@+id/action_thirdFragment_to_fourthFragment2"
            app:destination="@id/fourth_fragment" />
    fragment>
    <fragment
        android:id="@+id/fourth_fragment"
        android:name="com.devcomentry.moonynavbar.FourthFragment"
        android:label="fragment_fourth"
        tools:layout="@layout/fragment_fourth" />
navigation>
```

* In your activity i.e `MainActivity`

```
    private lateinit var navController: NavController

    lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = DataBindingUtil.setContentView(this, R.layout.activity_main)

        navController = findNavController(R.id.main_fragment)
        binding.moonyNavBar.setupWithNavController(navController)

    }


    override fun onSupportNavigateUp(): Boolean {
        navController.navigateUp()
        return true
    }
```

### Setup

```groovy
allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

dependencies {
	implementation 'com.github.doctor-blue:moony_nav_bar_android:v2.0.0'
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev-comentry.gitbook.io/docs/android/moonynavbar.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
