自定义 android 导航抽屉
custom android navigation drawer
我想使用导航抽屉创建一个 Android 应用程序,例如 Google 地图、Gmail ecc。我知道如何实现这一点,但我想要一些不同的东西。我希望导航栏没有完全隐藏,但它必须始终显示图标。
这个可以实现吗?谢谢
如果您想要创建导航抽屉,Android 设计库有一个名为 NavigationView 的新组件。 [Refer Link]
Chris Banes 提供的 Android 设计库的精彩教程可在此页面上找到。 GitHub - Cheesesquare
如果您想要自定义导航抽屉的感觉,您可能需要参考 Google I/O 应用程序。 github.com/google/iosched
编辑:考虑到您使用 NavigationView 并希望在选中时使文本透明,请在 /res/color/ 中添加一个新文件。我们将其命名为 nav_item_text.xml
在其中使用以下内容:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Text color when checked -->
<item android:color="#00000000" android:state_checked="true" />
<!-- Text color when not checked. Modify value to color of primary text. -->
<item android:color="#212121" />
</selector>
然后将其添加到您的 NavigationView 布局中:
app:itemTextColor="@color/nav_item_text"
现在看起来像:
<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/navView"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemTextColor="@color/nav_item_text"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav"/>
如果你想让文字永远消失:
app:itemTextColor="#00000000"
这可以使用 SlidingPaneLayout (https://developer.android.com/reference/android/support/v4/widget/SlidingPaneLayout.html) 而不是 NavigationDrawer 来实现。
这是一个 SlidingPaneLayout 的例子:
http://blog.sqisland.com/2015/01/partial-slidingpanelayout.html
我想使用导航抽屉创建一个 Android 应用程序,例如 Google 地图、Gmail ecc。我知道如何实现这一点,但我想要一些不同的东西。我希望导航栏没有完全隐藏,但它必须始终显示图标。
这个可以实现吗?谢谢
如果您想要创建导航抽屉,Android 设计库有一个名为 NavigationView 的新组件。 [Refer Link]
Chris Banes 提供的 Android 设计库的精彩教程可在此页面上找到。 GitHub - Cheesesquare
如果您想要自定义导航抽屉的感觉,您可能需要参考 Google I/O 应用程序。 github.com/google/iosched
编辑:考虑到您使用 NavigationView 并希望在选中时使文本透明,请在 /res/color/ 中添加一个新文件。我们将其命名为 nav_item_text.xml
在其中使用以下内容:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Text color when checked -->
<item android:color="#00000000" android:state_checked="true" />
<!-- Text color when not checked. Modify value to color of primary text. -->
<item android:color="#212121" />
</selector>
然后将其添加到您的 NavigationView 布局中:
app:itemTextColor="@color/nav_item_text"
现在看起来像:
<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/navView"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemTextColor="@color/nav_item_text"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav"/>
如果你想让文字永远消失:
app:itemTextColor="#00000000"
这可以使用 SlidingPaneLayout (https://developer.android.com/reference/android/support/v4/widget/SlidingPaneLayout.html) 而不是 NavigationDrawer 来实现。
这是一个 SlidingPaneLayout 的例子: http://blog.sqisland.com/2015/01/partial-slidingpanelayout.html