如何使用设计支持库将页脚添加到Android中的导航抽屉?
如何将页脚添加到如何使用设计支持库将页脚添加到Android中的导航抽屉?,android,navigation-drawer,Android,Navigation Drawer,如何将页脚添加到导航视图?在我的例子中,NavigationView项由菜单资源膨胀。最初我尝试添加一个线性布局作为页脚,但是NavigationView不可滚动,并且页脚被导航菜单项重叠。我想实现一个Google Play分级段,作为一个页脚,与下图完全相同: 导航\u drawer.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schema
导航视图
?在我的例子中,NavigationView
项由菜单资源膨胀。最初我尝试添加一个线性布局作为页脚,但是NavigationView
不可滚动,并且页脚被导航菜单项重叠。我想实现一个Google Play分级段,作为一个页脚,与下图完全相同:
导航\u drawer.xml
:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:id="@+id/toolbar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:title="@string/app_name" />
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/drawerLayout">
<FrameLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/containerView">
</FrameLayout>
<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/shitstuff"
app:itemTextColor="@color/green"
app:menu="@menu/drawermenu"
app:headerLayout="@layout/drawer_header"
android:layout_marginTop="-24dp">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
非常简单:
只需在NavigationView中包装所需的页脚。你可以以我的为例——效果很好
<android.support.design.widget.NavigationView
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:headerLayout="@layout/navigation_header"
app:itemTextColor="@android:color/black"
app:menu="@menu/drawer_view">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:clickable="true"
android:orientation="vertical">
<TextView
android:id="@+id/nav_footer_textview"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center"
android:text="Your Footer Text Here" />
</LinearLayout>
</android.support.design.widget.NavigationView>
您可以通过这种方式使用任何(或多或少复杂的)布局。
(请注意,此页脚不会滚动,将被修复)。您可以使用
在小屏幕上(和/或在陆地方向),NavigationView的菜单将与页脚重叠-尝试使用相对位置YouTube此功能正常,但底部抽屉位于顶部抽屉之上,因此您必须向其添加虚拟项。如何处理滚动,菜单项现在隐藏在此视图后面。如何从内部导航视图中删除水平标高?能否添加一些信息,说明这与其他答案有何区别?
<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/layout_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<!-- Activity content goes here -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="top"
app:menu="@menu/menu_navigation_drawer" />
<android.support.design.widget.NavigationView
android:id="@+id/navigation_drawer_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:menu="@menu/menu_navigation_drawer_bottom" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<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:itemIconTint="@color/colorAccent"
app:menu="@menu/activity_main_drawer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:clickable="true"
android:orientation="vertical">
<TextView
android:id="@+id/nav_footer_textview"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center"
android:text="Your Footer Text Here" />
</LinearLayout>
</android.support.design.widget.NavigationView>
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
TextView footerTV = (TextView) navigationView.findViewById(R.id.nav_footer_textview);
footerTV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Footer is clicked", Toast.LENGTH_SHORT).show();
}
});