i am new to android and trying to implement a main activity with tabs, each tab contains a fragment, and upon one of the fragments i would like the whole app bar to disappear (its intended to be a camera fragment) , leaving the certain fragment in FullScreen mode, this is what i have so far:
file : MainActivity.java 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       //this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
        ViewPager viewPager = findViewById(R.id.view_pager);
        viewPager.setAdapter(sectionsPagerAdapter);
        TabLayout tabs = findViewById(R.id.tabs);
        tabs.setupWithViewPager(viewPager);
        FloatingActionButton fab = findViewById(R.id.fab);
        final AppBarLayout bar = findViewById(R.id.appBarLayout2); // the app bar layout that i want gone
        tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab)
            {
                
            }
            @Override
            public void onTabUnselected(TabLayout.Tab tab)
            {
            }
            @Override
            public void onTabReselected(TabLayout.Tab tab)
            {
                onTabSelected(tab);
            }
        });
as you can see, i am trying to implement a tabs listener along with a ViewPager, i have tried implementing inside an if statement on the bar.position():
- ((AppCompatActivity) getActivity()).getSupportActionBar().hide(); - app crashes
 - getActionBar().hide() - returns null and also crashes
 - getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); - doesnt work
 
file : main_activity.xml
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".UIActivity">
    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/view_pager">
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="80dp"
            android:layout_height="50dp"
            android:layout_gravity="center"
            android:src="@mipmap/logo1" />
        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            app:tabIndicatorColor="#ffffff"
            app:tabIndicatorHeight="2dp" /><!-- #86B2E8 -->
    </com.google.android.material.appbar.AppBarLayout>
    <androidx.viewpager.widget.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="16dp"
        app:layout_constraintBottom_toBottomOf="@+id/view_pager"
        app:layout_constraintEnd_toEndOf="parent"
        app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.constraintlayout.widget.ConstraintLayout>
the cameraFragment.java and xml files are a standard files, i still do not know how i can hide the app bar when a user clicks on the camera tab, and return it once he swipes back to an another Fragment.