简体   繁体   English

将导航菜单移至顶部,操作栏下方 Android / XML

[英]Move navigation menu to the top, below action bar Android / XML

Hello Stackoverflow!你好 Stackoverflow!

I'm designing an android application, as you see in the photo below:我正在设计一个 android 应用程序,如下图所示:

Screenshot of Application run test应用运行测试截图

I cannot embed photos yet, please check the link我还不能嵌入照片,请检查链接

I have a navigation menu stuck bottom of the screen, I want to move this navigation bar to the top, under action bar which has Home title.我有一个navigation menu卡在屏幕底部,我想将此navigation bar移到顶部,在具有主页标题under action bar

I'm new to Android, thanks for the simple and full-way-to-solution responses!我是 Android 的新手,感谢您提供简单而完整的解决方案回复!

Bottom navigation menu XML:底部导航菜单 XML:

<item
    android:id="@+id/navigation_home"
    android:icon="@drawable/ic_action_remote"
    android:title="@string/title_home" />
<item
    android:id="@+id/navigation_tools"
    android:icon="@drawable/ic_tools_24"
    android:title="@string/title_Tools" />
<item
    android:id="@+id/navigation_dashboard"
    android:icon="@drawable/ic_dashboard_black_24dp"
    android:title="@string/title_dashboard" />

<item
    android:id="@+id/navigation_notifications"
    android:icon="@drawable/ic_notifications_black_24dp"
    android:title="@string/title_notifications" />

Main Activity:主要活动:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment_activity_main"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0"
        app:navGraph="@navigation/mobile_navigation" />

</androidx.constraintlayout.widget.ConstraintLayout>

I found this file too named as mobile navigation:我发现这个文件太命名为移动导航:

<?xml version="1.0" encoding="utf-8"?>
<navigation 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/mobile_navigation"
    app:startDestination="@+id/navigation_home">

    <fragment
        android:id="@+id/navigation_home"
        android:name="com.example.gsm.ui.home.HomeFragment"
        android:label="@string/title_home"
        tools:layout="@layout/fragment_home" />

    <fragment
        android:id="@+id/navigation_tools"
        android:name="com.example.gsm.ui.tools.toolsFragment"
        android:label="@string/title_Tools"
        tools:layout="@layout/fragment_home" />

    <fragment
        android:id="@+id/navigation_dashboard"
        android:name="com.example.gsm.ui.dashboard.DashboardFragment"
        android:label="@string/title_dashboard"
        tools:layout="@layout/fragment_dashboard" />

    <fragment
        android:id="@+id/navigation_notifications"
        android:name="com.example.gsm.ui.MapsFragment"
        android:label="@string/title_notifications"
        tools:layout="@layout/fragment_maps" />
</navigation>

Thanks for response谢谢回复

In your main activity XML,in your navigation bar, change app:layout_constraintBottom_toBottomOf="parent" to app:layout_constraintTop_toTopOf="parent"在您的主要活动 XML 中,在您的导航栏中,将app:layout_constraintBottom_toBottomOf="parent"更改为app:layout_constraintTop_toTopOf="parent"

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

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