Skip to content

Commit 91a5f30

Browse files
authored
Update README.md
1 parent 38a9aaf commit 91a5f30

1 file changed

Lines changed: 122 additions & 1 deletion

File tree

README.md

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,128 @@ dependencies {
2222
}
2323
```
2424
### How to use
25-
//TODO
25+
#### Via XML
26+
Create a layout named like this header_drawer.xml
27+
```XML
28+
<rebus.header.view.HeaderView xmlns:android="http://schemas.android.com/apk/res/android"
29+
xmlns:app="http://schemas.android.com/apk/res-auto"
30+
android:id="@+id/header_view"
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content"
33+
app:hv_add_icon="@drawable/ic_action_settings"
34+
app:hv_add_status_bar_height="true"
35+
app:hv_background_color="@color/colorPrimaryDark"
36+
app:hv_dialog_title="@string/account"
37+
app:hv_highlight_color="@color/colorAccent"
38+
app:hv_profile_avatar="@drawable/ic_placeholder"
39+
app:hv_profile_background="@drawable/ic_placeholder_bg"
40+
app:hv_profile_email="batman@gotham.city"
41+
app:hv_profile_username="Bruce Wayne"
42+
app:hv_show_add_button="true"
43+
app:hv_show_arrow="true"
44+
app:hv_show_gradient="true"
45+
app:hv_style="normal"
46+
app:hv_theme="light" />
47+
```
48+
And in your NavigationView
49+
50+
```XML
51+
<android.support.design.widget.NavigationView
52+
android:id="@+id/nav_view"
53+
android:layout_width="wrap_content"
54+
android:layout_height="match_parent"
55+
android:layout_gravity="start"
56+
app:headerLayout="@layout/header_drawer"
57+
app:menu="@menu/drawer" />
58+
```
59+
#### Manage Profiles
60+
The new HeaderView manage different profile and a new profile chooser inspired from YouTube android app
61+
- Create a profile
62+
```Java
63+
Profile profile = new Profile.Builder()
64+
.setId(2)
65+
.setUsername("Raphaël Bussa")
66+
.setEmail("raphaelbussa@gmail.com")
67+
.setAvatar("https://github.com/rebus007.png?size=512")
68+
.setBackground("https://images.unsplash.com/photo-1473220464492-452fb02e6221?dpr=2&auto=format&fit=crop&w=767&h=512&q=80&cs=tinysrgb&crop=")
69+
.build();
70+
```
71+
- Add a profile
72+
```Java
73+
headerView.addProfile(profile);
74+
```
75+
- Set a profile active
76+
```Java
77+
headerView.setProfileActive(2);
78+
```
79+
- Remove a profile
80+
```Java
81+
headerView.removeProfile(2);
82+
```
83+
- Get actual active profile
84+
```Java
85+
int activeProfileId = headerView.getProfileActive();
86+
```
87+
88+
#### Customize Profile Chooser
89+
You can also customize the profile chooser
90+
- Add bottom items
91+
```Java
92+
Item item = new Item.Builder()
93+
.setId(1)
94+
.setTitle("Remove all profile")
95+
.build();
96+
97+
headerView.addDialogItem(item);
98+
```
99+
- HighlightColor in dialog
100+
```
101+
headerView.setHighlightColor(ContextCompat.getColor(this, R.color.colorAccent));
102+
app:hv_highlight_color="@color/colorAccent"
103+
```
104+
- Change dialog title
105+
```
106+
headerView.setDialogTitle("Choose account");
107+
app:hv_dialog_title="Dialog title"
108+
```
109+
- Change dialog top icon
110+
```
111+
headerView.setAddIconDrawable(R.drawable.ic_action_settings);
112+
app:hv_add_icon="@drawable/ic_action_settings"
113+
```
114+
- Or hide dialog top icon
115+
```
116+
headerView.setShowAddButton(true);
117+
app:hv_show_add_button="true"
118+
```
119+
#### Loading image from network
120+
Just add this in your class Application (of course you can use your preferred libs for load images)
121+
```Java
122+
ImageLoader.init(new ImageLoader.ImageLoaderInterface() {
123+
@Override
124+
public void loadImage(Uri url, ImageView imageView, @ImageLoader.Type int type) {
125+
switch (type) {
126+
case ImageLoader.AVATAR:
127+
Glide.with(imageView.getContext())
128+
.load(url)
129+
.asBitmap()
130+
.placeholder(R.drawable.ic_placeholder)
131+
.error(R.drawable.ic_placeholder)
132+
.into(imageView);
133+
break;
134+
case ImageLoader.HEADER:
135+
Glide.with(imageView.getContext())
136+
.load(url)
137+
.asBitmap()
138+
.placeholder(R.drawable.ic_placeholder_bg)
139+
.error(R.drawable.ic_placeholder_bg)
140+
.into(imageView);
141+
break;
142+
}
143+
}
144+
145+
});
146+
```
26147

27148
### Sample
28149
Browse the sample code [here](https://github.com/rebus007/HeaderView/tree/master/app) or download sample app from the [Play Store](https://play.google.com/store/apps/details?id=rebus.header.view.sample)

0 commit comments

Comments
 (0)