Skip to content

Commit cc879f7

Browse files
author
Shrikanth Ravi
authored
Create README.md
1 parent bf257c7 commit cc879f7

File tree

1 file changed

+245
-0
lines changed

1 file changed

+245
-0
lines changed

README.md

+245
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
# Custom-Navigation-Drawer
2+
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
3+
4+
Custom Navigation Drawer Library for Android
5+
6+
Custom Navigation Drawer Library to navigate through option tabs with smooth slide.
7+
8+
It has smooth zoom-in, zoom-out animation when switched from one fragment to another.
9+
10+
Still in Active Development.
11+
12+
13+
14+
<table>
15+
<tr>
16+
<td>
17+
<img src="https://drive.google.com/uc?id=1lD36VKEDD6PIkFZo6nicjx_Du8qh5_kE" width="300">
18+
</td>
19+
<td>
20+
<img src="https://drive.google.com/uc?id=1TZHRXq-8Y75Pxk05YiF0tfQNSxhjrnKW" width="300">
21+
</td>
22+
</tr>
23+
</table>
24+
25+
### Version
26+
[![](https://jitpack.io/v/shrikanth7698/Custom-Navigation-Drawer.svg)](https://jitpack.io/#shrikanth7698/Custom-Navigation-Drawer)
27+
28+
### Installation
29+
30+
* **Gradle**
31+
32+
Add it in your root build.gradle at the end of repositories:
33+
```gradle
34+
allprojects {
35+
repositories {
36+
...
37+
maven { url 'https://jitpack.io' }
38+
}
39+
}
40+
```
41+
42+
Add the dependency in your app build.gradle
43+
```gradle
44+
dependencies {
45+
compile 'com.github.shrikanth7698:Custom-Navigation-Drawer:v0.0.1'
46+
}
47+
```
48+
49+
* **Maven**
50+
51+
Add the JitPack repository to your build file
52+
```gradle
53+
<repositories>
54+
<repository>
55+
<id>jitpack.io</id>
56+
<url>https://jitpack.io</url>
57+
</repository>
58+
</repositories>
59+
```
60+
61+
Add the dependency
62+
```gradle
63+
<dependency>
64+
<groupId>com.github.shrikanth7698</groupId>
65+
<artifactId>Custom-Navigation-Drawer</artifactId>
66+
<version>v0.0.1</version>
67+
</dependency>
68+
```
69+
70+
### Usage
71+
72+
Drop the Custom Navigation Drawer in your XML layout as is shown below:
73+
```xml
74+
<com.shrikanthravi.customnavigationdrawer2.widget.SNavigationDrawer
75+
android:layout_width="match_parent"
76+
android:layout_height="match_parent"
77+
android:id="@+id/navigationDrawer">
78+
<FrameLayout
79+
android:id="@+id/frameLayout"
80+
android:layout_width="match_parent"
81+
android:layout_height="match_parent"/>
82+
83+
</com.shrikanthravi.customnavigationdrawer2.widget.SNavigationDrawer>
84+
```
85+
And then in your Activity or fragment
86+
```java
87+
//Global Declaration
88+
SNavigationDrawer sNavigationDrawer;
89+
Class fragmentClass;
90+
public static Fragment fragment;
91+
92+
//Inside onCreate()
93+
94+
sNavigationDrawer = findViewById(R.id.navigationDrawer);
95+
96+
//Creating a list of menu Items
97+
98+
List<MenuItem> menuItems = new ArrayList<>();
99+
100+
//Use the MenuItem given by this library and not the default one.
101+
//First parameter is the title of the menu item and then the second parameter is the image which will be the background of the menu item.
102+
103+
menuItems.add(new MenuItem("News",R.drawable.news_bg));
104+
menuItems.add(new MenuItem("Feed",R.drawable.feed_bg));
105+
menuItems.add(new MenuItem("Messages",R.drawable.message_bg));
106+
menuItems.add(new MenuItem("Music",R.drawable.music_bg));
107+
108+
//then add them to navigation drawer
109+
110+
sNavigationDrawer.setMenuItemList(menuItems);
111+
fragmentClass = NewsFragment.class;
112+
try {
113+
fragment = (Fragment) fragmentClass.newInstance();
114+
} catch (Exception e) {
115+
e.printStackTrace();
116+
}
117+
if (fragment != null) {
118+
FragmentManager fragmentManager = getSupportFragmentManager();
119+
fragmentManager.beginTransaction().setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out).replace(R.id.frameLayout, fragment).commit();
120+
}
121+
122+
123+
124+
//Listener to handle the menu item click. It returns the position of the menu item clicked. Based on that you can switch between the fragments.
125+
126+
sNavigationDrawer.setOnMenuItemClickListener(new SNavigationDrawer.OnMenuItemClickListener() {
127+
@Override
128+
public void onMenuItemClicked(int position) {
129+
System.out.println("Position "+position);
130+
131+
switch (position){
132+
case 0:{
133+
fragmentClass = NewsFragment.class;
134+
break;
135+
}
136+
case 1:{
137+
fragmentClass = FeedFragment.class;
138+
break;
139+
}
140+
case 2:{
141+
fragmentClass = MessagesFragment.class;
142+
break;
143+
}
144+
case 3:{
145+
fragmentClass = MusicFragment.class;
146+
break;
147+
}
148+
149+
}
150+
151+
//Listener for drawer events such as opening and closing.
152+
sNavigationDrawer.setDrawerListener(new SNavigationDrawer.DrawerListener() {
153+
154+
@Override
155+
public void onDrawerOpened() {
156+
157+
}
158+
159+
@Override
160+
public void onDrawerOpening(){
161+
162+
}
163+
164+
@Override
165+
public void onDrawerClosing(){
166+
System.out.println("Drawer closed");
167+
168+
try {
169+
fragment = (Fragment) fragmentClass.newInstance();
170+
} catch (Exception e) {
171+
e.printStackTrace();
172+
}
173+
174+
if (fragment != null) {
175+
FragmentManager fragmentManager = getSupportFragmentManager();
176+
fragmentManager.beginTransaction().setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out).replace(R.id.frameLayout, fragment).commit();
177+
178+
}
179+
}
180+
181+
@Override
182+
public void onDrawerClosed() {
183+
184+
}
185+
186+
@Override
187+
public void onDrawerStateChanged(int newState) {
188+
System.out.println("State "+newState);
189+
}
190+
});
191+
}
192+
});
193+
```
194+
195+
### Customization
196+
197+
198+
```xml
199+
<com.shrikanthravi.customnavigationdrawer2.widget.SNavigationDrawer
200+
android:layout_width="match_parent"
201+
android:layout_height="match_parent"
202+
app:navigationDrawerBackgroundColor="#151515"
203+
app:appbarTitleTextColor="@android:color/white"
204+
app:HamMenuIconTintColor="@android:color/white"
205+
app:appbarColor="@android:color/black"
206+
app:primaryMenuItemTextColor="@android:color/white"
207+
app:secondaryMenuItemTextColor="@android:color/white"
208+
app:appbarTitleTextSize="7sp"
209+
app:primaryMenuItemTextSize="7sp"
210+
app:secondaryMenuItemTextSize="7sp"
211+
android:id="@+id/navigationDrawer">
212+
<FrameLayout
213+
android:id="@+id/frameLayout"
214+
android:background="@android:color/black"
215+
android:layout_width="match_parent"
216+
android:layout_height="match_parent"/>
217+
218+
</com.shrikanthravi.customnavigationdrawer2.widget.SNavigationDrawer>
219+
220+
```
221+
222+
223+
### License
224+
```
225+
MIT License
226+
227+
Copyright (c) 2018 Shrikanth Ravi
228+
229+
Permission is hereby granted, free of charge, to any person obtaining a copy
230+
of this software and associated documentation files (the "Software"), to deal
231+
in the Software without restriction, including without limitation the rights
232+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
233+
copies of the Software, and to permit persons to whom the Software is
234+
furnished to do so, subject to the following conditions:
235+
236+
The above copyright notice and this permission notice shall be included in all
237+
copies or substantial portions of the Software.
238+
239+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
240+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
241+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
242+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
244+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
245+
SOFTWARE.

0 commit comments

Comments
 (0)