簡體   English   中英

如何在導航抽屜本身中啟用“過度滾動”(頁面末尾的“跳動”動畫),以及如何更改圖標的顏色?

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

雖然我正在嘗試使用android studio的默認Navigation Drawer ActivityNavigation Drawer Activity構建應用程序。 一切工作都很好,但是我無法在抽屜中看到像Google Play商店應用程序那樣的over scroll mode 而且我也無法更改導航抽屜圖標的圖像顏色(每個圖標的顏色不同)。

所以,我的第一個問題是: 如何在抽屜中添加彈跳動畫?

而且,我的第二個問題是: 如何更改抽屜圖標的顏色?(每個圖標的顏色不同)

我的代碼(記住一件事,我正在使用Android Studio的默認“導航抽屜活動”)。

-: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;
}

-:不起作用的方法:-

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM