在Android Webview的相对布局中隐藏工具栏

时间:2018-06-18 02:02:42

标签: android-studio android-webview android-scrollview android-scroll

这是在activity_main.xml中。问题是当用户向下滚动时隐藏工具栏并在向上滚动时显示它。这可以在设计库的CoordinatorLayout和NestedScrollView中实现。但是我想在相对布局中使用它。

<android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FF9999FF">

        <RelativeLayout
            android:fitsSystemWindows="true"
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <Button
                android:id="@+id/button3"
                style="@style/Widget.AppCompat.Button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:background="@android:color/holo_blue_dark"
                android:onClick="rateMe"
                android:text="Update/Rate"
                android:textAppearance="@style/TextAppearance.AppCompat" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="0dp"
                android:layout_marginTop="0dp"
                android:background="#FF9999FF"
                android:minHeight="?attr/actionBarSize" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="fill_parent"
                android:layout_below="@id/toolbar"
                android:layout_height="wrap_content" />

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#FFF"
                android:id="@+id/frameLayout"
                android:layout_below="@id/tabs">

                <WebView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:id="@+id/webView"
                    android:layout_gravity="center" >

                </WebView>

            </FrameLayout>

            <com.google.android.gms.ads.AdView
                android:id="@+id/adView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_alignParentBottom="true"
                ads:adSize="BANNER"
                ads:adUnitId="@string/banner_ad_unit_id">

            </com.google.android.gms.ads.AdView>

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/drawer_frame"
            android:layout_width="260dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true">

            <ListView
                android:id="@+id/listView"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/imageView2"
                android:background="#eaeaea"
                android:choiceMode="singleChoice"
                android:divider="@android:color/transparent"
                android:dividerHeight="0dp">


            </ListView>

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="fill_parent"
                android:layout_height="150dp"
                android:layout_alignEnd="@+id/listView"
                android:layout_alignRight="@+id/listView"
                android:scaleType="centerCrop"
                android:src="@drawable/material" />

        </RelativeLayout>




    </android.support.v4.widget.DrawerLayout>

我不想更改嵌入webview的相对布局。可以将哪些函数/ java代码添加到mainActivity.java以隐藏自动滚动上的工具栏?我已经在堆栈交换上得到了一些答案,但无法实现。

0 个答案:

没有答案