简体   繁体   English

如何在导航抽屉本身中启用“过度滚动”(页面末尾的“跳动”动画),以及如何更改图标的颜色?

[英]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 . 虽然我正在尝试使用android studio的默认Navigation Drawer ActivityNavigation 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. 一切工作都很好,但是我无法在抽屉中看到像Google Play商店应用程序那样的over scroll mode 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). 我的代码(记住一件事,我正在使用Android Studio的默认“导航抽屉活动”)。

-: XML :- -: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 :- -: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" 01. app:itemIconTint="@color/colorAccent"

OverScroll

01. android:overScrollMode="always" 01. android:overScrollMode="always"

02. drawer.setOverScrollMode(DrawerLayout.OVER_SCROLL_ALWAYS); 02. drawer.setOverScrollMode(DrawerLayout.OVER_SCROLL_ALWAYS);

03. navigationView.setOverScrollMode(NavigationView.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);} 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);} 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);} 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);} 07. for (int i = 0; i < navigationView.getChildCount(); i++) { navigationView.getChildAt(i).setOverScrollMode(NavigationView.OVER_SCROLL_ALWAYS);}

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

drawerView.itemIconTintList = null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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