MaterialNavigationDrawer
介绍:
Material风格的侧滑菜单控件,需要14+ API 和 android support v7 (Toolbar)
运行效果:
使用说明:
activity中:
public class MyActivity extends MaterialNavigationDrawer {
@Override
public Fragment getCurrentFragment(int position) {
switch(position) {
case MaterialNavigationDrawer.SECTION_START:
return new Fragment1();
case MaterialNavigationDrawer.SECTION_START + 1:
return new Fragment2();
case MaterialNavigationDrawer.BOTTOM_SECTION_START:
return new FragmentSettings();
default: return new Fragment();
}
}
@Override
public void init(Bundle savedInstanceState) {
// set cover background
this.setDrawerBackground(this.getResources().getDrawable(R.drawable.mat1));
// set user photo and data
this.setUserPhoto(this.getResources().getDrawable(R.drawable.photo));
this.setUsername("NeoKree");
this.setUserEmail("neokree@gmail.com");
// add your sections
this.addSection(this.newSection("Section 1"));
this.addSection(this.newSection("Section 2",this.getResources().getDrawable(R.drawable.ic_mic_white_24dp)));
this.addBottomSection(this.newBottomSection("Settings",this.getResources().getDrawable(R.drawable.ic_settings_black_24dp)));
}
@Override
public String getCurrentTitle(int position) {
switch(position) {
case MaterialNavigationDrawer.SECTION_START:
return "My First Section";
case MaterialNavigationDrawer.SECTION_START + 1:
return "My Second Section";
case MaterialNavigationDrawer.BOTTOM_SECTION_START:
return "Settings";
default: return "";
}
}
}
style文件中:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/light_blue_500</item>
<item name="colorPrimaryDark">@color/light_blue_800</item>
<item name="colorAccent">@color/grey_1000</item>
<item name="windowActionBar">false</item>
</style>
</resources>
注意重写的是init方法不是onCreate方法。
已下载
0