我目前有一个现有项目,我希望在其中实施导航抽屉活动。目前,如果我添加了一个新的导航抽屉的活动,它会生成以下布局:将导航抽屉活动模板添加到现有项目中
然而,除了布局上面,我想我的导航抽屉完全一样,它看起来像默认模板一个这个(由资产净值的标头,等):
我如何去实现呢?我是Android开发新手。
编辑:我只需要改变我的应用程序的主题,以实现我想要的东西
我目前有一个现有项目,我希望在其中实施导航抽屉活动。目前,如果我添加了一个新的导航抽屉的活动,它会生成以下布局:将导航抽屉活动模板添加到现有项目中
然而,除了布局上面,我想我的导航抽屉完全一样,它看起来像默认模板一个这个(由资产净值的标头,等):
我如何去实现呢?我是Android开发新手。
编辑:我只需要改变我的应用程序的主题,以实现我想要的东西
在这个环节可能是答案或指导你在这,看看这个
创建新抽屉活动:
文件 - >新建 - >活动 - >抽屉式导航活动
private void setupNavigationDrawer() {
//if you want to update the items at a later time it is recommended to keep it in a variable
PrimaryDrawerItem item1 = new PrimaryDrawerItem().withIdentifier(0).withName(R.string.drawer_item_home).withIcon(getResources().getDrawable(R.drawable.ic_home_white_24dp));
PrimaryDrawerItem item2 = new PrimaryDrawerItem().withIdentifier(1).withName(R.string.drawer_item_login).withIcon(getResources().getDrawable(R.drawable.ic_account_circle_white_24dp));
PrimaryDrawerItem item3 = new PrimaryDrawerItem().withIdentifier(2).withName(R.string.drawer_item_movies).withIcon(getResources().getDrawable(R.drawable.ic_movie_white_24dp));
PrimaryDrawerItem item4 = new PrimaryDrawerItem().withIdentifier(3).withName(R.string.drawer_item_trailers).withIcon(getResources().getDrawable(R.drawable.ic_videocam_white_24dp));
PrimaryDrawerItem item5 = new PrimaryDrawerItem().withIdentifier(4).withName(R.string.drawer_item_theatres).withIcon(getResources().getDrawable(R.drawable.ic_theaters_white_24dp));
PrimaryDrawerItem item6 = new PrimaryDrawerItem().withIdentifier(5).withName(R.string.drawer_item_location).withIcon(getResources().getDrawable(R.drawable.ic_location_on_white_24dp));
SecondaryDrawerItem item7 = (SecondaryDrawerItem) new SecondaryDrawerItem().withIdentifier(6).withName(R.string.drawer_item_about_us).withIcon(FontAwesome.Icon.faw_info_circle);
SecondaryDrawerItem item8 = (SecondaryDrawerItem) new SecondaryDrawerItem().withIdentifier(7).withName(R.string.drawer_item_contact_us).withIcon(FontAwesome.Icon.faw_whatsapp);
SecondaryDrawerItem item9 = (SecondaryDrawerItem) new SecondaryDrawerItem().withIdentifier(8).withName(R.string.drawer_item_feedback).withIcon(FontAwesome.Icon.faw_commenting);
SecondaryDrawerItem item10 = (SecondaryDrawerItem) new SecondaryDrawerItem().withIdentifier(9).withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_wrench);
// Create the AccountHeader
AccountHeader headerResult = new AccountHeaderBuilder()
.withActivity(this)
.withHeaderBackground(R.color.colorMaterialDark)
.addProfiles(
new ProfileDrawerItem().withName(getResources().getString(R.string.app_name)).withEmail(getResources().getString(R.string.email_id)).withIcon(getResources().getDrawable(R.drawable.profile))
)
.withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
@Override
public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
//Any activity or Intent
}
})
.build();
//Create the drawer and remember the `Drawer` result object
Drawer result = new DrawerBuilder()
.withActivity(this)
.withAccountHeader(headerResult)
.withToolbar(toolbar)
.addDrawerItems(
item1, item2, item3, item4, item5, item6,
new SectionDrawerItem().withName("Extras"),
item7, item8, item9, item10
)
//Set onClick options for drawer item click
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
// do something with the clicked item :D
switch (position) {
//Home
case 1: {
break;
}
//Login
case 2: {
//Login Activity
break;
}
case 3: {
//Third activity
break;
}
case 4: {
break;
}
case 5: {
break;
}
//Location
case 6: {
break;
}
//About us
case 8: {
break;
}
//Contact Us
case 9: {
break;
}
//Feedback
case 10: {
break;
}
//Settings
case 11:{
break;
}
}
return true;
}
})
.build();
result.addStickyFooterItem(new PrimaryDrawerItem().withName("Visit us again")); //Adding footer to nav drawer
}
你将不得不添加以下行到android studio中的build.gradle文件
compile('com.mikepenz:materialdrawer:[email protected]') {
transitive = true
}
compile 'com.mikepenz:fontawesome-typeface:[email protected]'