My app consist of MainActivity and 2 fragments. MainActivity works as Navigation Host.
In my app I've disabled global ActionBar, instead I set my own in MainFragment
val toolbar: Toolbar = v.findViewById(R.id.toolbar)
(activity as AppCompatActivity).setSupportActionBar(toolbar)
Toolbar is also included in XML file for this fragment:
<include
android:id="@+id/include"
layout="@layout/toolbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
The problem's when I go to other fragment's screen Toolbar isn't showing.
MainActivity XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity"
android:orientation="vertical">
<fragment
android:id="@+id/fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
</LinearLayout>
Where is the problem?
question from:
https://stackoverflow.com/questions/65939756/support-action-bar-visible-only-in-one-fragment 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…