use of android.support.design.internal.NavigationMenuPresenter in project Dxditor by kimi2009.
the class MainActivity method setNavigationMenuLineStyle.
/**
* 给 NavigationView 的Menu的分割线 设置高度和颜色
*
* @param navigationView
* @param color
* @param height
*/
public static void setNavigationMenuLineStyle(NavigationView navigationView, @ColorInt final int color, final int height) {
try {
Field fieldByPressenter = navigationView.getClass().getDeclaredField("mPresenter");
fieldByPressenter.setAccessible(true);
NavigationMenuPresenter menuPresenter = (NavigationMenuPresenter) fieldByPressenter.get(navigationView);
Field fieldByMenuView = menuPresenter.getClass().getDeclaredField("mMenuView");
fieldByMenuView.setAccessible(true);
final NavigationMenuView mMenuView = (NavigationMenuView) fieldByMenuView.get(menuPresenter);
mMenuView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
@Override
public void onChildViewAttachedToWindow(View view) {
RecyclerView.ViewHolder viewHolder = mMenuView.getChildViewHolder(view);
if (viewHolder != null && "SeparatorViewHolder".equals(viewHolder.getClass().getSimpleName()) && viewHolder.itemView != null) {
if (viewHolder.itemView instanceof FrameLayout) {
FrameLayout frameLayout = (FrameLayout) viewHolder.itemView;
View line = frameLayout.getChildAt(0);
line.setBackgroundColor(color);
line.getLayoutParams().height = height;
line.setLayoutParams(line.getLayoutParams());
}
}
}
@Override
public void onChildViewDetachedFromWindow(View view) {
}
});
} catch (Throwable e) {
e.printStackTrace();
}
}
Aggregations