将悬停效果添加到导航菜单

时间:2017-12-09 11:21:58

标签: java android navigation-drawer drawerlayout android-navigation-drawer

我在导航抽屉的链接中进行了设计附加,其中包含一个悬停在菜单项上方,但其宽度大于导航调色板。

悬停效果的设计

![enter image description here

编辑:悬停是历史记录中的白色背景框。选中时它应该是这样的。

XML

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@drawable/background_slider"
    android:fitsSystemWindows="false">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="20dp">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/nav_item_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>


</android.support.design.widget.NavigationView>

爪哇

RecyclerView recycler = findViewById(R.id.nav_item_list);
    LinearLayoutManager layout = new LinearLayoutManager(this);
    recycler.setLayoutManager(layout);
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recycler.getContext(),
            layout.getOrientation());
    dividerItemDecoration.setDrawable(ContextCompat.getDrawable(this, R.drawable.item_divider));
    recycler.addItemDecoration(dividerItemDecoration);

    String[] englishTitles = getResources().getStringArray(R.array.nav_english_items);
    String[] urduTitles = getResources().getStringArray(R.array.nav_urdu_items);
    int[] icons = new int[englishTitles.length];
    TypedArray navIcons = getResources().obtainTypedArray(R.array.nav_icons);
    try {
        for (int i = 0; i < icons.length; i++) {
            icons[i] = navIcons.getResourceId(i, -1);
        }
    } finally {
        navIcons.recycle();
    }
    recycler.setAdapter(new NavigationItemAdapter(this, englishTitles, urduTitles, icons, this));

P.S。:我也尝试了以下内容。

Change the color of a checked menu item in a navigation drawer

Android navigation drawer, change text/hover color

我真的需要尽快做到这一点 如果有任何遗漏,请提前感谢!

0 个答案:

没有答案