Reputation: 11
I am trying to add border between two different items on Navigation Drawer. I have used Mikepenz Material Drawer ( https://github.com/mikepenz/MaterialDrawer) for Naviagation drawer.
Here is the Screenshot. i just want that border line in Navigation Drawer, I dont want that heading like "Downloaders" and "Share and Rate"
Take a look at Screenshot here :
I have added this line in my main activity to differentiate downloaders and others : new SectionDrawerItem().withName(R.string.drawer_item_section_header),
Here is my java code for navigation Drawer:
//Navigation Drawer
headerResult = new AccountHeaderBuilder()
.withActivity(this)
.withHeaderBackground(R.color.colorPrimary)
.withSelectionListEnabledForSingleProfile(false)
.withAlternativeProfileHeaderSwitching(false)
.withCompactStyle(false)
.withDividerBelowHeader(false)
.withProfileImagesVisible(true)
.withTypeface(typeface)
.addProfiles(new ProfileDrawerItem().withIcon(R.mipmap.ic_launcher).withName(getResources().getString(R.string.app_name)).withEmail(getResources()
.getString(R.string.developer_email)))
.build();
resultDrawer = new DrawerBuilder()
.withActivity(this)
.withSelectedItem(-1)
.withFullscreen(true)
.withAccountHeader(headerResult)
.withActionBarDrawerToggle(true)
.withCloseOnClick(true)
.withMultiSelect(false)
.withTranslucentStatusBar(true)
.withToolbar(mToolbar)
.addDrawerItems(
new PrimaryDrawerItem().withSelectable(false).withName(R.string.app_name).withTypeface(typeface),
new PrimaryDrawerItem().withSelectable(false).withName("Downloads").withIcon(R.drawable.ic_inst).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (placeholderLayout.getVisibility() == View.VISIBLE) {
placeholderLayout.setVisibility(View.GONE);
recyclerLayout.setVisibility(View.VISIBLE);
setUpRecyclerView();
}
return false;
}
}).withTypeface(typeface),
new SectionDrawerItem().withName(R.string.drawer_item_section_header),
new PrimaryDrawerItem().withSelectable(false).withName("Story Downloader").withIcon(R.drawable.ic_whatshot_black_24dp).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
Intent intent = new Intent(MainActivity.this,SplashActivity.class);
startActivity(intent);
return false;
}
}).withTypeface(typeface),
new PrimaryDrawerItem().withSelectable(false).withName("WhatsApp Downloader").withIcon(R.drawable.ic_wapp).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
Intent intent = new Intent(MainActivity.this,WaActivity.class);
startActivity(intent);
return false;
}
}).withTypeface(typeface),
new PrimaryDrawerItem().withSelectable(false).withName("Twitter Downloader").withIcon(R.drawable.ic_tweet).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
Intent intent = new Intent(MainActivity.this,TweetActivity.class);
startActivity(intent);
return false;
}
}).withTypeface(typeface),
new PrimaryDrawerItem().withSelectable(false).withName("Facebook Downloader").withIcon(R.drawable.ic_facebook_logo).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
Intent intent = new Intent(MainActivity.this,FbActivity.class);
startActivity(intent);
return false;
}
}).withTypeface(typeface),
new SectionDrawerItem().withName(R.string.drawer_item_section_share),
new PrimaryDrawerItem().withSelectable(false).withName("Recommend to Friends").withIcon(R.drawable.ic_share_black_24dp).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
final String shareappPackageName = getPackageName();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Check out Social Downloader App at: https://play.google.com/store/apps/details?id=" + shareappPackageName);
sendIntent.setType("text/plain");
startActivity(sendIntent);
return false;
}
}).withTypeface(typeface),
new PrimaryDrawerItem().withSelectable(false).withName("Rate Us").withIcon(R.drawable.ic_thumb_up_black_24dp).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
final String appPackageName = getPackageName();
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
return false;
}
}).withTypeface(typeface),
new PrimaryDrawerItem().withSelectable(false).withName("Help").withIcon(R.drawable.ic_help_black_24dp).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
Intent intent = new Intent(MainActivity.this, IntroActivity.class);
startActivity(intent);
return false;
}
}).withTypeface(typeface),
new PrimaryDrawerItem().withSelectable(false).withName("Privacy Policy").withIcon(R.drawable.ic_info_black_24dp).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
.setTitle("PRIVACY POLICY")
.setMessage(R.string.privacy_message)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setIcon(R.drawable.ic_info_black_24dp)
.show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setScroller(new Scroller(MainActivity.this));
textView.setVerticalScrollBarEnabled(true);
textView.setMovementMethod(new ScrollingMovementMethod());
return false;
}
}).withTypeface(typeface),
new PrimaryDrawerItem().withSelectable(false).withName("Feedback").withIcon(R.drawable.ic_feedback_black_24dp).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
PackageManager manager = getApplicationContext().getPackageManager();
PackageInfo info = null;
try {
info = manager.getPackageInfo(getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String version = info.versionName;
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{getResources().getString(R.string.developer_email)});
i.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.app_name) + version);
i.putExtra(Intent.EXTRA_TEXT,
"\n" + " Device :" + getDeviceName() +
"\n" + " System Version:" + Build.VERSION.SDK_INT +
"\n" + " Display Height :" + height + "px" +
"\n" + " Display Width :" + width + "px" +
"\n\n" + "Have a problem? Please share it with us and we will do our best to solve it!" +
"\n");
startActivity(Intent.createChooser(i, "Send Email"));
return false;
}
}).withTypeface(typeface),
new PrimaryDrawerItem().withSelectable(false).withName("Exit").withIcon(R.drawable.ic_exit_to_app_black_24dp).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
finish();
return false;
}
}).withTypeface(typeface)
).
withSavedInstance(savedInstanceState)
.build();
loadInterstitialAd();
}
Upvotes: 0
Views: 2214
Reputation: 2131
Make sure that you give each group an id and it will works like a magic
<group android:checkableBehavior="single"
android:id="@+id/group1">
<item
android:id="@+id/nav_about"
android:icon="@drawable/ic_about"
android:title="About" />
</group>
<group android:checkableBehavior="single"
android:id="@+id/group2">
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings"
android:title="Settings" />
</group>
Upvotes: 1
Reputation: 347
Normally You need to do it in your menu xml file: simply put each menu items in separate groups, each group must have an id(each group is separated by a divider)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="@+id/item1">
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings"
android:title="Settings"/>
</group>
<group
android:id="@+id/item2">
<item
android:id="@+id/nav_info"
android:icon="@drawable/ic_info"
android:title="Info"/>
</group>
</menu>
Update:
I just checked the github of the drawer you used. I am not familiar with it, but I noticed a method:
result.addItem(new DividerDrawerItem());
maybe it will help, sorry I can't help more, but you will probably find everything you need in the documentations and in his source code example
Upvotes: 0