如何在mikepenz materialdrawer库的帐户配置文件部分添加分隔符?
我可以使用new DividerDrawerItem()
将分隔线添加到抽屉本身,但无法将分隔线添加到配置文件部分。我怎样才能做到这一点?
如何在mikepenz materialdrawer库的帐户配置文件部分添加分隔符?
我可以使用new DividerDrawerItem()
将分隔线添加到抽屉本身,但无法将分隔线添加到配置文件部分。我怎样才能做到这一点?
hmmm to get a Divider inside the Profiles section the easiest would be to create an item similar to the DividerDrawerItem but it should also implement IProfile so you can add it to the accounts too, and you just need to make it not selectable so it won't show up in the header and can't be selected.
public class AccountDividerDrawerItem extends AbstractDrawerItem<AccountDividerDrawerItem, AccountDividerDrawerItem.ViewHolder> implements IProfile<AccountDividerDrawerItem> {
@Override
public int getType() {
return R.id.material_drawer_profile_item_divider;
}
@Override
@LayoutRes
public int getLayoutRes() {
return com.mikepenz.materialdrawer.R.layout.material_drawer_item_divider;
}
@Override
public void bindView(ViewHolder viewHolder) {
Context ctx = viewHolder.itemView.getContext();
//set the identifier from the drawerItem here. It can be used to run tests
viewHolder.itemView.setId(hashCode());
//define how the divider should look like
viewHolder.view.setClickable(false);
viewHolder.view.setEnabled(false);
viewHolder.view.setMinimumHeight(1);
ViewCompat.setImportantForAccessibility(viewHolder.view,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
//set the color for the divider
viewHolder.divider.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(ctx, com.mikepenz.materialdrawer.R.attr.material_drawer_divider, com.mikepenz.materialdrawer.R.color.material_drawer_divider));
//call the onPostBindView method to trigger post bind view actions (like the listener to modify the item if required)
onPostBindView(this, viewHolder.itemView);
}
@Override
public ViewHolderFactory<ViewHolder> getFactory() {
return new ItemFactory();
}
@Override
public AccountDividerDrawerItem withName(String name) {
return null;
}
@Override
public StringHolder getName() {
return null;
}
@Override
public AccountDividerDrawerItem withEmail(String email) {
return null;
}
@Override
public StringHolder getEmail() {
return null;
}
@Override
public AccountDividerDrawerItem withIcon(Drawable icon) {
return null;
}
@Override
public AccountDividerDrawerItem withIcon(Bitmap bitmap) {
return null;
}
@Override
public AccountDividerDrawerItem withIcon(@DrawableRes int iconRes) {
return null;
}
@Override
public AccountDividerDrawerItem withIcon(String url) {
return null;
}
@Override
public AccountDividerDrawerItem withIcon(Uri uri) {
return null;
}
@Override
public AccountDividerDrawerItem withIcon(IIcon icon) {
return null;
}
@Override
public ImageHolder getIcon() {
return null;
}
public static class ItemFactory implements ViewHolderFactory<ViewHolder> {
public ViewHolder create(View v) {
return new ViewHolder(v);
}
}
protected static class ViewHolder extends RecyclerView.ViewHolder {
private View view;
private View divider;
private ViewHolder(View view) {
super(view);
this.view = view;
this.divider = view.findViewById(com.mikepenz.materialdrawer.R.id.material_drawer_divider);
}
}
}
Just 2 things!
AbstractDrawerItem
.getType()
method, because this has to be unique and can't be reused accross items. (Internal cache handling of the RecyclerView
).Note that: R.id.material_drawer_profile_item_divider
does not exist and must replace with an arbitrary local identifier
! so create ids.xml
file invalues
directory and add this line to that:
<item name="material_drawer_profile_item_divider" type="id" />