0

In android navigationdraweractivity, I placed a VideoView inside a fragment and said fragment is having a nested ScrollView.

Whenever I scroll up the VideoView, it hides the actionbar.

I tried the following code.

scrollview.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
    @Override
    public void onScrollChanged() {
        ((AppCompatActivity) getActivity()).getSupportActionBar().show();
    }
});

The Layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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:paddingBottom="15dp"
    android:background="@color/white"
    android:id="@+id/scrollview"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/scroll_example">

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:orientation="vertical">

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="50dp"
       android:background="@color/colorAccent"
       android:layout_below="@+id/app_bar"
       android:gravity="center_horizontal"
       android:layout_gravity="bottom"
       android:orientation="horizontal">

      <ImageButton
          android:layout_width="46dp"
          android:layout_height="match_parent"
          android:id="@+id/imgbtnimg"
          android:background="#00000000"
          android:src="@drawable/gallery" />

      <ImageButton
          android:layout_width="46dp"
          android:layout_height="match_parent"
          android:id="@+id/imgbtnVideo"
          android:background="#00000000"
          android:src="@drawable/video"/>
   </LinearLayout>


   <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/text_margin"
        android:layout_marginRight="@dimen/text_margin"
        android:layout_marginBottom="@dimen/text_margin"
         android:layout_marginTop="@dimen/text_margin"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/txtname"
        android:layout_gravity="fill"
        android:paddingBottom="15dp"
        android:text="name" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

this link of the code worked for me for navigation drawer but my action bar also hides not got solution for that

the actual code for fragment is scroll_example.xml

xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="snap"
android:fitsSystemWindows="true">




<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar0"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:fitsSystemWindows="true"
    android:theme="@style/Theme.AppCompat.Light">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar0"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:contentInsetLeft="0dp"
        android:contentInsetRight="0dp"
        android:contentInsetStart="0dp"
        android:minHeight="?attr/actionBarSize"
        android:padding="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetRight="0dp"
        app:contentInsetStart="0dp"
        app:layout_scrollFlags="scroll|enterAlways"
        android:theme="@style/Theme.AppCompat.Light">

   <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_collapseMode="pin"
        app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">


        <ViewPager
            android:id="@+id/pager"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />




   </android.support.design.widget.CollapsingToolbarLayout>

Bhagyashri
  • 182
  • 1
  • 15

0 Answers0