【发布时间】:2021-10-27 16:40:55
【问题描述】:
我已经有一个导航栏可以毫无问题地为我更改片段:
<?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"
android:label="@string/app_name"
app:startDestination="@+id/navigation_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" />
</navigation>
这是我的 Activity_Main.xml:
<?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="0dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="@color/background"
app:itemIconSize="27dp"
app:itemIconTint="@color/red"
app:itemTextColor="@color/red"
app:layout_constraintTop_toTopOf="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>
我的导航栏很容易为我交换片段,但我想禁用导航栏,我需要一些按钮来完成导航栏曾经为我做的事情。
我是 Android/XML 新手,Internet 中片段之间的交易没有与我的文件和代码同步,如果我将内容添加到框架布局中,我的所有设计都会搞砸。
【问题讨论】:
-
我推荐使用新的谷歌技术 NavigationUI developer.android.com/guide/navigation/navigation-ui 简单、自动并且有很多例子。像这样看起来另一个片段打开
Navigation.findNavController(binding.root).navigate(FirstFragmentDirection.actionNavigateToSecondFragment())
标签: java android xml android-fragments