Search in sources :

Example 1 with NavigationMenuPresenter

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();
    }
}
Also used : Field(java.lang.reflect.Field) FrameLayout(android.widget.FrameLayout) NavigationMenuPresenter(android.support.design.internal.NavigationMenuPresenter) RecyclerView(android.support.v7.widget.RecyclerView) NavigationView(android.support.design.widget.NavigationView) IMainpageView(itor.topnetwork.com.dxditor.view.IMainpageView) View(android.view.View) WebView(android.webkit.WebView) NavigationMenuView(android.support.design.internal.NavigationMenuView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RadarView(itor.topnetwork.com.dxditor.myview.RadarView) RaderView(itor.topnetwork.com.dxditor.myview.RaderView) NavigationMenuView(android.support.design.internal.NavigationMenuView)

Aggregations

NavigationMenuPresenter (android.support.design.internal.NavigationMenuPresenter)1 NavigationMenuView (android.support.design.internal.NavigationMenuView)1 NavigationView (android.support.design.widget.NavigationView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 WebView (android.webkit.WebView)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 RadarView (itor.topnetwork.com.dxditor.myview.RadarView)1 RaderView (itor.topnetwork.com.dxditor.myview.RaderView)1 IMainpageView (itor.topnetwork.com.dxditor.view.IMainpageView)1 Field (java.lang.reflect.Field)1