简体   繁体   中英

How to enable Over scroll (Bounce animation on page end) in Navigation Drawer itself and how to change the icon's color?

Though I'm trying to build an app with the Navigation Drawer Activity from android studio's default Navigation Drawer Activity . Everything is working fine on that, but I can't see the over scroll mode in my drawer like the Google play store app. And also I can't change the image color of the navigation drawer icons (Different colors for each icon).

So, my first question is : How to add the bounce animation in the drawer?

And, my second question is : How to change the color of the drawer icons?(Different colors for each icon)

My codes (Remember one thing that I'm using Android Studio's default Navigation Drawer Activity).

-: XML :-

activity_main

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <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:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

activity_main_drawer

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
        <item android:title="@string/drawer_subtitle_01">
            <menu>
                <item
                    android:checkableBehavior="single"
                    android:id="@+id/1st"
                    android:icon="@drawable/ic_1st"
                    android:title="@string/drawer_1st" />
            </menu>
        </item>
    </group>
</menu>

-: JAVA :-

onCreate

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);

onClick

@Override
public boolean onNavigationItemSelected(MenuItem item) {
      int id = item.getItemId();
      if (id == R.id.1st) {
         toast.setText("1st option selected");
         toast.show();
      }
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

-: Not working methodS :-

IconColors

01. app:itemIconTint="@color/colorAccent"

OverScroll

01. android:overScrollMode="always"

02. drawer.setOverScrollMode(DrawerLayout.OVER_SCROLL_ALWAYS);

03. navigationView.setOverScrollMode(NavigationView.OVER_SCROLL_ALWAYS);

04. for (int i = 0; i < drawer.getChildCount(); i++) { drawer.getChildAt(i).setOverScrollMode(View.OVER_SCROLL_ALWAYS);}

05. for (int i = 0; i < navigationView.getChildCount(); i++) { navigationView.getChildAt(i).setOverScrollMode(View.OVER_SCROLL_ALWAYS);}

06. for (int i = 0; i < drawer.getChildCount(); i++) { drawer.getChildAt(i).setOverScrollMode(DrawerLayout.OVER_SCROLL_ALWAYS);}

07. for (int i = 0; i < navigationView.getChildCount(); i++) { navigationView.getChildAt(i).setOverScrollMode(NavigationView.OVER_SCROLL_ALWAYS);}

要将抽屉图标的颜色更改回其原始颜色,只需添加以下代码(科特琳):

drawerView.itemIconTintList = null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM