本文整理汇总了Java中com.mikepenz.materialdrawer.model.SectionDrawerItem类的典型用法代码示例。如果您正苦于以下问题:Java SectionDrawerItem类的具体用法?Java SectionDrawerItem怎么用?Java SectionDrawerItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SectionDrawerItem类属于com.mikepenz.materialdrawer.model包,在下文中一共展示了SectionDrawerItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reloadDrawerItems
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
@Override
protected List<IDrawerItem> reloadDrawerItems(Realm realm, boolean showOnlyUnread) {
List<Feed> feeds = state.getStartDrawerItem().getFeeds(realm, showOnlyUnread);
List<IDrawerItem> drawerItems = new ArrayList<>((feeds != null ? feeds.size() : 0) + 1);
if (state.isFeedSelected())
return drawerItems;
drawerItems.add(new SectionDrawerItem()
.withDivider(false)
.withName(state.getStartDrawerItem().getName()));
if (feeds != null) {
for (Feed feed : feeds) {
PrimaryDrawerItem drawerItem = new TreeItemDrawerItem(feed);
drawerItem.withIdentifier(feed.getId());
drawerItem.withBadge(feed.getUnreadCount());
drawerItem.withSetSelected(state.getEndDrawerItem() != null && state.getEndDrawerItem().getId() == feed.getId());
drawerItems.add(drawerItem);
}
}
return drawerItems;
}
示例2: addGiveawayItems
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
/**
* Add all Navbar icons related to giveaways.
*/
private void addGiveawayItems(SteamGiftsUserData account) {
// All different giveaway views
drawer.addItems(
new SectionDrawerItem().withName(R.string.navigation_giveaways).withDivider(!account.isLoggedIn()),
new PrimaryDrawerItem().withName(R.string.navigation_giveaways_all).withIdentifier(R.string.navigation_giveaways_all).withIcon(FontAwesome.Icon.faw_gift));
// If we're logged in, we can look at group and wishlist giveaways.
if (account.isLoggedIn()) {
drawer.addItems(
new PrimaryDrawerItem().withName(R.string.navigation_giveaways_group).withIdentifier(R.string.navigation_giveaways_group).withIcon(FontAwesome.Icon.faw_users),
new PrimaryDrawerItem().withName(R.string.navigation_giveaways_wishlist).withIdentifier(R.string.navigation_giveaways_wishlist).withIcon(FontAwesome.Icon.faw_heart),
new PrimaryDrawerItem().withName(R.string.navigation_giveaways_recommended).withIdentifier(R.string.navigation_giveaways_recommended).withIcon(FontAwesome.Icon.faw_thumbs_up));
}
drawer.addItems(new PrimaryDrawerItem().withName(R.string.navigation_giveaways_new).withIdentifier(R.string.navigation_giveaways_new).withIcon(FontAwesome.Icon.faw_refresh));
}
示例3: addDiscussionItems
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
/**
* Add all discussion-related items.
*/
private void addDiscussionItems(SteamGiftsUserData account, String mode) {
if ("full".equals(mode)) {
// Full mode: Show all different categories in the navbar
drawer.addItem(new SectionDrawerItem().withName(R.string.navigation_discussions).withDivider(true));
for (DiscussionListFragment.Type type : DiscussionListFragment.Type.values()) {
// We only want to have 'Created Discussions' if we're actually logged in.
if (type == DiscussionListFragment.Type.CREATED && !account.isLoggedIn())
continue;
drawer.addItem(new PrimaryDrawerItem().withName(type.getNavbarResource()).withIdentifier(type.getNavbarResource()).withIcon(type.getIcon()));
}
} else if ("compact".equals(mode)) {
// Compact mode: we only add a single item called 'Discussions' that links to all discussions,
// and there's a menu item in the 'discussions' list to switch between different categories.
drawer.addItem(new PrimaryDrawerItem().withName(R.string.navigation_discussions).withIdentifier(DiscussionListFragment.Type.ALL.getNavbarResource()).withIcon(DiscussionListFragment.Type.ALL.getIcon()));
}
}
示例4: buildMenuList
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
private void buildMenuList() {
ArrayList<IDrawerItem> menuList = new ArrayList<IDrawerItem>();
int parserSpecificFeatureCount = 0;
mDrawerItem_Parser.withName(mParser.getName());
menuList.add(mDrawerItem_Parser);
menuList.add(mDrawerItem_Catalog);
menuList.add(mDrawerItem_Library);
menuList.add(mDrawerItem_Favorites);
menuList.add(mDrawerItem_History);
menuList.add(mDrawerItem_Downloads);
menuList.add(new SectionDrawerItem().withName(mParser.getName() + " Specific Features"));
if (mParser.isShowAllSupported) {
menuList.add(mDrawerItem_AllManga);
parserSpecificFeatureCount++;
}
if (mParser.isGenreSortSupported) {
menuList.add(mDrawerItem_Genres);
parserSpecificFeatureCount++;
}
if (mParser.isLatestSortSupported) {
menuList.add(mDrawerItem_LatestReleases);
parserSpecificFeatureCount++;
}
if (parserSpecificFeatureCount == 0)
menuList.remove(menuList.size() - 1);
else
menuList.add(new SectionDrawerItem().withName("MAV Features"));
//menuList.add(mDrawerItem_ServerSearch);
menuList.add(mDrawerItem_Settings);
menuList.add(mDrawerItem_Patreon);
menuList.add(mDrawerItem_Version);
drawerResult.setItems(menuList);
if (miniResult != null)
miniResult.createItems();
}
示例5: setupNavigationDrawer
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
private void setupNavigationDrawer() {
ProfileDrawerItem section = new ProfileDrawerItem()
.withSetSelected(false)
.withSetSelected(false)
.withEnabled(false);
PrimaryDrawerItem joyType0DrawerItem = new PrimaryDrawerItem().withName("Basic Gamepad").withTag(KEY_BASIC_GAMEPAD_1).withLevel(2);
PrimaryDrawerItem joyType1DrawerItem = new PrimaryDrawerItem().withName("Assault Horizon").withTag(KEY_ASSAULT_HORIZON).withLevel(2);
PrimaryDrawerItem joyType2DrawerItem = new PrimaryDrawerItem().withName("Awesomenauts").withTag(KEY_AWESOMENAUTS).withLevel(2);
PrimaryDrawerItem joyType3DrawerItem = new PrimaryDrawerItem().withName("BombSquad").withTag(KEY_BOMBSQUAD).withLevel(2);
PrimaryDrawerItem joyType4DrawerItem = new PrimaryDrawerItem().withName("Final Fantasy XIII").withTag(KEY_FINAL_FANTASY_XIII).withLevel(2);
SectionDrawerItem sectionDrawerItem = new SectionDrawerItem().withName("Joystick Type").withTextColorRes(R.color.colorAccent);
PrimaryDrawerItem deviceDrawerItem = new PrimaryDrawerItem().withName("Device Connection").withTag(KEY_DEVICE_CONNECTION).withIcon(GoogleMaterial.Icon.gmd_devices);
PrimaryDrawerItem settingsDrawerItem = new PrimaryDrawerItem().withName("Settings").withTag("settings").withIcon(GoogleMaterial.Icon.gmd_settings);
ndMenu = new DrawerBuilder()
.withActivity(this)
.withToolbar(tbMain)
.withCloseOnClick(true)
.withFireOnInitialOnClick(true)
.withSelectedItemByPosition(6)
.withDelayDrawerClickEvent(300)
.withDisplayBelowStatusBar(true)
.withTranslucentStatusBar(false)
.withOnDrawerItemClickListener(this)
.addDrawerItems(section, deviceDrawerItem, settingsDrawerItem, sectionDrawerItem, joyType0DrawerItem, joyType1DrawerItem, joyType2DrawerItem, joyType3DrawerItem, joyType4DrawerItem)
.build();
}
示例6: onCreateView
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
// don't look at this layout it's just a listView to show how to handle the keyboard
View view = inflater.inflate(R.layout.fragment_simple_sample, container, false);
result = new DrawerBuilder()
.withActivity(getActivity())
.withRootView((ViewGroup) view.findViewById(R.id.rootView))
.withDisplayBelowStatusBar(false)
.withSavedInstance(savedInstanceState)
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).withIdentifier(1),
new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new SectionDrawerItem().withName(R.string.drawer_item_section_header),
new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog),
new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false),
new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github),
new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)
)
.buildForFragment();
TextView textView = (TextView) view.findViewById(R.id.title);
textView.setText(getArguments().getString(KEY_TITLE));
result.getDrawerLayout().setFitsSystemWindows(false);
result.getSlider().setFitsSystemWindows(false);
return view;
}
示例7: onCreate
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_collapsing_toolbar);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbarLayout.setTitle(getString(R.string.drawer_item_collapsing_toolbar_drawer));
headerResult = new AccountHeaderBuilder()
.withActivity(this)
.withCompactStyle(false)
.withHeaderBackground(R.drawable.header)
.withSavedInstance(savedInstanceState)
.build();
result = new DrawerBuilder()
.withActivity(this)
.withAccountHeader(headerResult)
.withToolbar(toolbar)
.withFullscreen(true)
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).withIdentifier(1),
new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new SectionDrawerItem().withName(R.string.drawer_item_section_header),
new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog),
new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false),
new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github),
new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)
)
.withSavedInstance(savedInstanceState)
.build();
fillFab();
loadBackdrop();
}
示例8: onCreate
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_custom_container_dark_toolbar);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.drawer_item_custom_container_drawer);
//Create the drawer
result = new DrawerBuilder(this)
//this layout have to contain child layouts
.withRootView(R.id.drawer_container)
.withToolbar(toolbar)
.withDisplayBelowStatusBar(false)
.withActionBarDrawerToggleAnimated(true)
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home),
new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new SectionDrawerItem().withName(R.string.drawer_item_section_header),
new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog),
new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false),
new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github),
new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)
)
.withSavedInstance(savedInstanceState)
.build();
}
示例9: getDrawerItems
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
private ArrayList<IDrawerItem> getDrawerItems() {
SectionDrawerItem profileItem = new SectionDrawerItem().withName(R.string.profiles)
.withTextColorRes(R.color.accentColor).setDivider(false);
PrimaryDrawerItem addItem = new PrimaryDrawerItem().withName(R.string.add_profile)
.withIdentifier(Action.ADD.ordinal()).withIcon(GoogleMaterial.Icon.gmd_add_circle_outline)
.withCheckable(false);
SectionDrawerItem settingItem = new SectionDrawerItem().withName(R.string.settings)
.withTextColorRes(R.color.accentColor);
PrimaryDrawerItem recoveryItem = new PrimaryDrawerItem().withName(R.string.recovery)
.withIdentifier(Action.RECOVERY.ordinal()).withIcon(GoogleMaterial.Icon.gmd_restore)
.withCheckable(false);
PrimaryDrawerItem aboutItem = new PrimaryDrawerItem().withName(R.string.about)
.withIdentifier(Action.ABOUT.ordinal()).withIcon(GoogleMaterial.Icon.gmd_info_outline)
.withCheckable(false);
ArrayList<IDrawerItem> items = new ArrayList<>();
items.add(profileItem);
items.addAll(getProfileList());
items.add(addItem);
items.add(settingItem);
items.add(recoveryItem);
items.add(aboutItem);
return items;
}
示例10: setupDrawer
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
private void setupDrawer() {
drawer = new DrawerBuilder()
.withActivity(this)
.withTranslucentStatusBar(true)
.withFooterDivider(false)
.withStickyFooter(R.layout.nav_footer)
.addDrawerItems(
new SectionDrawerItem().withName("Explore").withDivider(false),
new PrimaryDrawerItem().withName("Movies")
.withIcon(new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_movie_alt).sizeDp(24)),
new PrimaryDrawerItem().withName("TV Series")
.withIcon(new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_tv_alt_play).sizeDp(24)),
new PrimaryDrawerItem().withName("Watch Later")
.withIcon(new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_calendar_check).sizeDp(24)),
new SectionDrawerItem().withName("About"),
new SecondaryDrawerItem().withName("Settings")
.withIcon(new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_settings).sizeDp(24).colorRes(R.color.colorLightGray)),
new SecondaryDrawerItem().withName("Open Source Acknowledgements")
.withIcon(new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_github_alt).sizeDp(24).colorRes(R.color.colorLightGray)))
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
Util.debugLog(TAG, "onItemClick: Position " + position);
switch (position) {
case 1:
Bundle bundleMovies = new Bundle();
bundleMovies.putBoolean("IS_MOVIES", true);
switchFragment(new MainFragment(), bundleMovies, "MOVIES_FRAG");
break;
case 2:
Bundle bundleTv = new Bundle();
bundleTv.putBoolean("IS_MOVIES", false);
switchFragment(new MainFragment(), bundleTv, "TV_FRAG");
break;
case 3:
Intent watchLaterIntent = new Intent(BaseActivity.this, WatchLaterActivity.class);
startActivity(watchLaterIntent);
break;
case 5:
switchFragment(new SettingsFragment(), null, "SETTINGS_FRAG");
break;
case 6:
switchFragment(new OpenSourceFragment(), null, "OPEN_SOURCE_FRAG");
break;
}
return false;
}
})
.build();
}
示例11: initDrawer
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
private void initDrawer(){
new DrawerBuilder().withActivity(this).build();
// Create the AccountHeader
profileItem = new ProfileDrawerItem().withName(" ").withEmail(" ").withIcon(getResources().getDrawable(R.drawable.empty_profile));
headerResult = new AccountHeaderBuilder()
.withActivity(this)
.withHeaderBackground(R.color.primary)
.withSelectionListEnabledForSingleProfile(false)
.addProfiles(
profileItem
)
.build();
//create the drawer and remember the `Drawer` result object
drawer = new DrawerBuilder()
.withActivity(this)
.withToolbar(mToolbar)
.withAccountHeader(headerResult)
.withItemAnimator(new AlphaCrossFadeAnimator())
.addDrawerItems(
new SectionDrawerItem().withName(R.string.time_tracker).withDivider(false),
new PrimaryDrawerItem().withIdentifier(1).withName(R.string.last_30_days).withIcon(R.drawable.icon_histogram),
new SectionDrawerItem().withName(R.string.settings).withDivider(false),
new PrimaryDrawerItem().withIdentifier(2).withName(R.string.i_beacon).withIcon(R.drawable.icon_ibeacon).withBadge(AppPreferences.getBeaconDetectionState()? "On":"Off").withBadgeStyle(new BadgeStyle().withTextColor(ContextCompat.getColor(this, R.color.medium_grey_text_color))),
new PrimaryDrawerItem().withIdentifier(3).withName(R.string.geofence).withIcon(R.drawable.icon_geofence).withBadge(AppPreferences.getGeofenceDetectionState()? "On":"Off").withBadgeStyle(new BadgeStyle().withTextColor(ContextCompat.getColor(this, R.color.medium_grey_text_color))),
new DividerDrawerItem(),
new PrimaryDrawerItem().withIdentifier(4).withName(R.string.feedback),
// new PrimaryDrawerItem().withIdentifier(5).withName(R.string.terms_and_cond),
new PrimaryDrawerItem().withIdentifier(6).withName(R.string.log_out)
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
Intent intent;
switch ((int)drawerItem.getIdentifier()){
case 1:
intent = new Intent(MainActivity.this, LastMonthTimeEntriesActivity.class);
startActivity(intent);
break;
case 2:
intent = new Intent(MainActivity.this, BeaconSettingsActivity.class);
startActivity(intent);
break;
case 3:
intent = new Intent(MainActivity.this, GeofenceSettingsActivity.class);
startActivity(intent);
break;
case 4:
PackageInfo pInfo = null;
try {
pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
Intent emailIntent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + getResources().getString(R.string.app_name) + " - Version: " + pInfo.versionName + "&body=" + "" + "&to=" + EMAIL_ADDRESS);
emailIntent.setData(data);
startActivity(emailIntent);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
break;
case 5:
// Intent intent = new Intent(MainActivity.this, LastMonthTimeEntriesActivity.class);
// startActivity(intent);
break;
case 6:
logoutAction();
break;
}
return false;
}
})
.withCloseOnClick(true)
.build();
drawer.setSelection(-1);
}
示例12: onCreate
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
//supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_nontranslucent);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.drawer_item_non_translucent_status_drawer);
// Create a few sample profile
result = new DrawerBuilder()
.withActivity(this)
.withTranslucentStatusBar(false)
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home),
new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new SectionDrawerItem().withName(R.string.drawer_item_section_header),
new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog),
new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false),
new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github),
new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem instanceof Nameable) {
Toast.makeText(NonTranslucentDrawerActivity.this, ((Nameable) drawerItem).getName().getText(NonTranslucentDrawerActivity.this), Toast.LENGTH_SHORT).show();
}
return false;
}
})
.withSelectedItemByPosition(2)
.withSavedInstance(savedInstanceState)
.build();
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
示例13: onCreate
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_fullscreen_dark_toolbar);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setBackgroundColor(Color.BLACK);
toolbar.getBackground().setAlpha(90);
getSupportActionBar().setTitle(R.string.drawer_item_fullscreen_drawer);
//Create the drawer
result = new DrawerBuilder()
.withActivity(this)
.withFullscreen(true)
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).withIdentifier(1),
new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
//add some more items to get a scrolling list
new SectionDrawerItem().withName(R.string.drawer_item_section_header),
new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog),
new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false),
new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github),
new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn),
new SectionDrawerItem().withName(R.string.drawer_item_section_header),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye)
)
.withSavedInstance(savedInstanceState)
.build();
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
/*
//USE THIS CODE TO GET A FULL TRANSPARENT STATUS BAR
//YOU HAVE TO UNCOMMENT THE setWindowFlag too.
if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, true);
}
if (Build.VERSION.SDK_INT >= 19) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
if (Build.VERSION.SDK_INT >= 21) {
setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, false);
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
*/
if (Build.VERSION.SDK_INT >= 19) {
result.getDrawerLayout().setFitsSystemWindows(false);
}
}
示例14: onCreate
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.drawer_item_advanced_drawer);
// Create a few sample profile
profile = new ProfileDrawerItem().withName("Mike Penz").withEmail("[email protected]").withIcon(getResources().getDrawable(R.drawable.profile));
profile2 = new ProfileDrawerItem().withName("Max Muster").withEmail("[email protected]").withIcon(getResources().getDrawable(R.drawable.profile2)).withIdentifier(2);
profile3 = new ProfileDrawerItem().withName("Felix House").withEmail("[email protected]").withIcon(getResources().getDrawable(R.drawable.profile3));
profile4 = new ProfileDrawerItem().withName("Mr. X").withEmail("[email protected]").withIcon(getResources().getDrawable(R.drawable.profile4)).withIdentifier(4);
profile5 = new ProfileDrawerItem().withName("Batman").withEmail("[email protected]").withIcon(getResources().getDrawable(R.drawable.profile5));
// Create the AccountHeader
buildHeader(false, savedInstanceState);
//Create the drawer
result = new DrawerBuilder()
.withActivity(this)
.withToolbar(toolbar)
.withAccountHeader(headerResult) //set the AccountHeader we created earlier for the header
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home),
//here we use a customPrimaryDrawerItem we defined in our sample app
//this custom DrawerItem extends the PrimaryDrawerItem so it just overwrites some methods
new OverflowMenuDrawerItem().withName(R.string.drawer_item_menu_drawer_item).withDescription(R.string.drawer_item_menu_drawer_item_desc).withMenu(R.menu.fragment_menu).withOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(AdvancedActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show();
return false;
}
}).withIcon(GoogleMaterial.Icon.gmd_filter_center_focus),
new CustomPrimaryDrawerItem().withBackgroundRes(R.color.accent).withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withDescription("This is a description").withIcon(FontAwesome.Icon.faw_eye),
new CustomUrlPrimaryDrawerItem().withName(R.string.drawer_item_fragment_drawer).withDescription(R.string.drawer_item_fragment_drawer_desc).withIcon("https://avatars3.githubusercontent.com/u/1476232?v=3&s=460"),
new SectionDrawerItem().withName(R.string.drawer_item_section_header),
new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cart_plus),
new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_database).withEnabled(false),
new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github),
new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withSelectedIconColor(Color.RED).withIconTintingEnabled(true).withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_plus).actionBar().paddingDp(5).colorRes(R.color.material_drawer_dark_primary_text)).withTag("Bullhorn"),
new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false)
) // add the items we want to use with our Drawer
.withOnDrawerNavigationListener(new Drawer.OnDrawerNavigationListener() {
@Override
public boolean onNavigationClickListener(View clickedView) {
//this method is only called if the Arrow icon is shown. The hamburger is automatically managed by the MaterialDrawer
//if the back arrow is shown. close the activity
AdvancedActivity.this.finish();
//return true if we have consumed the event
return true;
}
})
.addStickyDrawerItems(
new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog).withIdentifier(10),
new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github)
)
.withSavedInstance(savedInstanceState)
.build();
}
示例15: onCreate
import com.mikepenz.materialdrawer.model.SectionDrawerItem; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
// Handle Toolbar
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.drawer_item_compact_header);
// Create a few sample profile
final IProfile profile = new ProfileDrawerItem().withName("Mike Penz").withEmail("[email protected]").withIcon(R.drawable.profile);
final IProfile profile2 = new ProfileDrawerItem().withName("Max Muster").withEmail("[email protected]").withIcon(R.drawable.profile2);
final IProfile profile3 = new ProfileDrawerItem().withName("Felix House").withEmail("[email protected]").withIcon(R.drawable.profile3);
final IProfile profile4 = new ProfileDrawerItem().withName("Mr. X").withEmail("[email protected]").withIcon(R.drawable.profile4);
final IProfile profile5 = new ProfileDrawerItem().withName("Batman").withEmail("[email protected]").withIcon(R.drawable.profile5);
// Create the AccountHeader
headerResult = new AccountHeaderBuilder()
.withActivity(this)
.withCompactStyle(true)
.withHeaderBackground(R.drawable.header)
.addProfiles(
profile,
profile2,
profile3,
profile4,
profile5,
//don't ask but google uses 14dp for the add account icon in gmail but 20dp for the normal icons (like manage account)
new ProfileSettingDrawerItem().withName("Add Account").withDescription("Add new GitHub Account").withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_plus).actionBar().paddingDp(5).colorRes(R.color.material_drawer_dark_primary_text)).withIdentifier(PROFILE_SETTING),
new ProfileSettingDrawerItem().withName("Manage Account").withIcon(GoogleMaterial.Icon.gmd_settings)
)
.withSavedInstance(savedInstanceState)
.build();
//Create the drawer
result = new DrawerBuilder()
.withActivity(this)
.withAccountHeader(headerResult) //set the AccountHeader we created earlier for the header
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).withIdentifier(1),
new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye).withIdentifier(5),
new SectionDrawerItem().withName(R.string.drawer_item_section_header),
new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog),
new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false),
new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github),
new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem != null && drawerItem.getIdentifier() == 1) {
startSupportActionMode(new ActionBarCallBack());
findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(CompactHeaderDrawerActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
}
if (drawerItem instanceof Nameable) {
toolbar.setTitle(((Nameable) drawerItem).getName().getText(CompactHeaderDrawerActivity.this));
}
return false;
}
})
.withSavedInstance(savedInstanceState)
.build();
// set the selection to the item with the identifier 5
if (savedInstanceState == null) {
result.setSelection(5, false);
}
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}