title: How to set a different toolbar and hide previous toolbar in fragment
body: <p>I am trying to inflate different toolbars in my fragments. Although I am able to inflate different toolbars for different fragments the problem is with MainActivity toolbar i am unable to hide it I have used</p>
  <pre><code> (activity as AppCompatActivity).supportActionBar?.hide() 
  </code></pre>
  <p>but it only hides the fragment toolbar, not the MainActivity toolbar I Want to hide the MainActivity toolbar.</p>
  <p>My code</p>
  <p>fragment</p>
  <pre><code>class SearchFragment : Fragment() {
  
      override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                                savedInstanceState: Bundle?): View? {
  
          val view = inflater.inflate(R.layout.fragment_search, container, false)
          val toolbar = view.findViewById&lt;Toolbar&gt;(R.id.toolbar_search)
  
          (activity as AppCompatActivity).setSupportActionBar(toolbar)
          setHasOptionsMenu(true)
  //        (activity as AppCompatActivity).supportActionBar?.hide()
  
          return view
  
      }
  </code></pre>
  <blockquote>
  <p>Xml</p>
  </blockquote>
  <pre><code>&lt;androidx.coordinatorlayout.widget.CoordinatorLayout
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;&gt;
  
      &lt;com.google.android.material.appbar.AppBarLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;&gt;
  
          &lt;androidx.appcompat.widget.Toolbar
              android:id=&quot;@+id/toolbar&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;56dp&quot;
              app:titleTextColor=&quot;#000000&quot;
              app:title=&quot;MainActivity&quot;
              app:elevation=&quot;8dp&quot; /&gt;
  
      &lt;/com.google.android.material.appbar.AppBarLayout&gt;
      
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>