如何将分隔符添加到mikepenz materialdrawer库的帐户个人资料部分?
我可以使用new DividerDrawerItem()
向抽屉本身添加分隔符,但无法在配置文件部分添加分隔符。我怎么能这样做?
答案 0 :(得分:1)
要在“个人档案”部分中获取分隔符,最简单的方法是创建一个类似于DividerDrawerItem的项目,但它也应该实现IProfile,以便您也可以将其添加到帐户中,并且您只需要使其不可选择,它不会出现在标题中,也无法被选中。
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);
}
}
}
只需2件事!
AbstractDrawerItem
定义的正确通用类型。getType()
方法中查找标识符,因为这必须是唯一的,并且不能跨项目重复使用。 (RecyclerView
)的内部缓存处理。 注意:R.id.material_drawer_profile_item_divider
不存在,必须替换为任意本地identifier
!所以在ids.xml
目录中创建values
文件并将此行添加到:{/ p>
<item name="material_drawer_profile_item_divider" type="id" />