如何在android活动中添加顶部抽屉和底部导航?

如何在android活动中添加顶部抽屉和底部导航?,android,android-activity,bottomnavigationview,Android,Android Activity,Bottomnavigationview,如何在整个应用程序中添加顶部抽屉和底部选项卡导航? 我试图将android studio中的2个活动及其引发的设计问题结合起来。底部导航不起作用 例如,您可以通过这种方式在整个项目中实现一点您想要的 将其用作activity\u main.xml类似于MainActivity.java类 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="h

如何在整个应用程序中添加顶部抽屉和底部选项卡导航? 我试图将android studio中的2个活动及其引发的设计问题结合起来。底部导航不起作用


例如,您可以通过这种方式在整个
项目中实现一点您想要的

将其用作
activity\u main.xml
类似于
MainActivity.java

<?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_home"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="@dimen/dp_180"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/top_lay"
                android:layout_width="match_parent"
                android:layout_height="@dimen/nav_header_height"
                android:background="@color/colorPrimary"
                android:orientation="vertical"
                android:theme="@style/ThemeOverlay.AppCompat.Dark">

                <RelativeLayout
                    android:id="@+id/userimageLay"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true">

                    <com.team.helperclasses.CircleImageView
                        android:id="@+id/userimage"
                        android:layout_width="@dimen/dp_100"
                        android:layout_height="@dimen/dp_100"
                        android:src="@mipmap/side_menu_profile_"
                        app:civ_border_color="@color/colorPrimary"
                        app:civ_border_overlay="true"
                        app:civ_border_width="1dp" />
                </RelativeLayout>
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/editProfile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/top_lay"
                android:paddingBottom="@dimen/dp_5"
                android:paddingTop="@dimen/dp_5">

                <TextView
                    android:id="@+id/editProfileText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/editProfileImage"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="@dimen/dp_8"
                    android:text="@string/editProfile"
                    android:textColor="@color/dull_black"
                    android:textSize="@dimen/sp_18" />

                <ImageView
                    android:id="@+id/editProfileImage"
                    android:layout_width="@dimen/dp_45"
                    android:layout_height="@dimen/dp_45"
                    android:layout_centerHorizontal="true"
                    android:src="@mipmap/side_menu_profile" />
            </RelativeLayout>

            <View
                android:id="@+id/editProfiledivider"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/editProfile"
                android:background="@color/light_black" />

            <RelativeLayout
                android:id="@+id/sharedWall"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/editProfile"
                android:paddingBottom="@dimen/dp_5"
                android:paddingTop="@dimen/dp_5">

                <TextView
                    android:id="@+id/sharedWallText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/shareWallImage"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="@dimen/dp_8"
                    android:text="@string/sharedWall"
                    android:textColor="@color/dull_black"
                    android:textSize="@dimen/sp_18" />

                <ImageView
                    android:id="@+id/shareWallImage"
                    android:layout_width="@dimen/dp_45"
                    android:layout_height="@dimen/dp_45"
                    android:layout_centerHorizontal="true"
                    android:src="@mipmap/wall" />
            </RelativeLayout>

            <View
                android:id="@+id/shareWallDivider"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/sharedWall"
                android:background="@color/light_black" />

            <RelativeLayout
                android:id="@+id/changeLang"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/shareWallDivider"
                android:paddingBottom="@dimen/dp_5"
                android:paddingTop="@dimen/dp_5">

                <TextView
                    android:id="@+id/changeLangText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/changeLangImage"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="@dimen/dp_8"
                    android:text="@string/changeLanguage"
                    android:textColor="@color/dull_black"
                    android:textSize="@dimen/sp_18" />

                <ImageView
                    android:id="@+id/changeLangImage"
                    android:layout_width="@dimen/dp_45"
                    android:layout_height="@dimen/dp_45"
                    android:layout_centerHorizontal="true"
                    android:src="@mipmap/language" />
            </RelativeLayout>

            <View
                android:id="@+id/changeLangdivider"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/changeLang"
                android:background="@color/light_black" />

            <RelativeLayout
                android:id="@+id/logout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/changeLangdivider"
                android:paddingBottom="@dimen/dp_5"
                android:paddingTop="@dimen/dp_5">

                <TextView
                    android:id="@+id/logoutText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/logoutImage"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="@dimen/dp_8"
                    android:text="@string/logout"
                    android:textColor="@color/dull_black"
                    android:textSize="@dimen/sp_18" />

                <ImageView
                    android:id="@+id/logoutImage"
                    android:layout_width="@dimen/dp_45"
                    android:layout_height="@dimen/dp_45"
                    android:layout_centerHorizontal="true"
                    android:src="@mipmap/log_out" />
            </RelativeLayout>
        </RelativeLayout>
    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>  
&
content\u home.xml
中,您可以根据应用程序中的需求定义内容

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/content_home"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.team.activities.Home"
    tools:showIn="@layout/app_bar_home">

    <RelativeLayout
        android:id="@+id/fragment_space"
        android:name="com.presence.fragments.HomeFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_lay" />


    <LinearLayout
        android:id="@+id/bottom_lay"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_50"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:background="@color/colorPrimary"
        android:layoutDirection="ltr"
        android:orientation="horizontal">

        <RelativeLayout
            android:id="@+id/tab_create"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/image_create"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/text_create"
                android:layout_centerHorizontal="true"
                android:src="@mipmap/create" />

            <TextView
                android:id="@+id/text_create"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="@string/create"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_10" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/tab_received"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/image_received"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/text_received"
                android:layout_centerHorizontal="true"
                android:src="@mipmap/recived" />

            <TextView
                android:id="@+id/text_received"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="@string/received"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_10" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/tab_sent"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/image_sent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/text_sent"
                android:layout_centerHorizontal="true"
                android:src="@mipmap/sent" />

            <TextView
                android:id="@+id/text_sent"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="@string/sent"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_10" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/tab_website"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/image_website"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/text_travel"
                android:layout_centerHorizontal="true"
                android:src="@mipmap/web" />

            <TextView
                android:id="@+id/text_travel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="@string/booking"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_10" />
        </RelativeLayout>
    </LinearLayout>

</RelativeLayout>  


试试这个,希望它能帮助您。

我们无法知道您遇到了什么样的设计问题。你能用一些相关的代码和设计截图更好地解释一下吗。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/content_home"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.team.activities.Home"
    tools:showIn="@layout/app_bar_home">

    <RelativeLayout
        android:id="@+id/fragment_space"
        android:name="com.presence.fragments.HomeFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_lay" />


    <LinearLayout
        android:id="@+id/bottom_lay"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_50"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:background="@color/colorPrimary"
        android:layoutDirection="ltr"
        android:orientation="horizontal">

        <RelativeLayout
            android:id="@+id/tab_create"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/image_create"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/text_create"
                android:layout_centerHorizontal="true"
                android:src="@mipmap/create" />

            <TextView
                android:id="@+id/text_create"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="@string/create"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_10" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/tab_received"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/image_received"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/text_received"
                android:layout_centerHorizontal="true"
                android:src="@mipmap/recived" />

            <TextView
                android:id="@+id/text_received"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="@string/received"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_10" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/tab_sent"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/image_sent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/text_sent"
                android:layout_centerHorizontal="true"
                android:src="@mipmap/sent" />

            <TextView
                android:id="@+id/text_sent"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="@string/sent"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_10" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/tab_website"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/image_website"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/text_travel"
                android:layout_centerHorizontal="true"
                android:src="@mipmap/web" />

            <TextView
                android:id="@+id/text_travel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="@string/booking"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_10" />
        </RelativeLayout>
    </LinearLayout>

</RelativeLayout>