工具栏隐藏在特定的webview URL上无效

问题描述 投票:0回答:1

我有一个ID为“toolbar_footer”的工具栏。如何为特定网址隐藏此工具栏,例如:'index.php'。我的项目主要活动的部分在下面给出了我已经尝试了很多次并且无法使其与给定的答案一起正常工作,因此使用xml布局代码更新代码。

请帮忙..我这个问题持续数月了

private class UriWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            String host = Uri.parse(url).getHost();

            urlData = url;


            if (target_url_prefix.equals(host)) {
                if(url.contains("index.php") || url.contains("login.php") || url.contains("register.php"))          {
                    System.out.println("This is my target url 2");
                    System.out.println(url);
                    //showToolBar = false;
                    findViewById(R.id.toolbar_footer).setVisibility(View.GONE);
                }
                else
                {
                    findViewById(R.id.toolbar_footer).setVisibility(View.VISIBLE);
                }
                if (mWebviewPop != null) {
                    mWebviewPop.setVisibility(View.GONE);
                    mContainer.removeView(mWebviewPop);
                    mWebviewPop = null;
                }

                return false;

            }

            boolean result = UrlHander.checkUrl(MainActivity.this, url);
            if (result) {
                ProgressDialogHelper.dismissProgress();
            } else {
                currentUrl = url;

                if (!show_content) {
                    if(url.contains("index.php") || url.contains("login.php") || url.contains("register.php"))          {
                        System.out.println("This is my target url 2");
                        System.out.println(url);
                        //showToolBar = false;
                        findViewById(R.id.toolbar_footer).setVisibility(View.GONE);
                        findViewById(R.id.fab).setVisibility(View.GONE);
                    }
                    else
                    {
                        findViewById(R.id.toolbar_footer).setVisibility(View.VISIBLE);
                        findViewById(R.id.fab).setVisibility(View.VISIBLE);
                    }

                    ProgressDialogHelper.showProgress(MainActivity.this);
                }
            }
            return result;
        }


        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            if (!NetworkHandler.isNetworkAvailable(view.getContext())) {
                view.loadUrl("file:///android_asset/NoInternet.html");

            }
            hideStatusBar();
            ProgressDialogHelper.dismissProgress();
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            if (!NetworkHandler.isNetworkAvailable(view.getContext())) {
                view.loadUrl("file:///android_asset/NoInternet.html");
            }
            hideStatusBar();
            ProgressDialogHelper.dismissProgress();
        }

        @Override
        public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
            super.onReceivedHttpError(view, request, errorResponse);
            if (!NetworkHandler.isNetworkAvailable(view.getContext())) {
                view.loadUrl("file:///android_asset/NoInternet.html");
            }
            hideStatusBar();
            ProgressDialogHelper.dismissProgress();
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if(url.contains("index.php") || url.contains("login.php") || url.contains("register.php"))          {
                System.out.println("This is my target url 2");
                System.out.println(url);
                //showToolBar = false;
                findViewById(R.id.toolbar_footer).setVisibility(View.GONE);
                findViewById(R.id.fab).setVisibility(View.GONE);
            }
            else
            {
                findViewById(R.id.toolbar_footer).setVisibility(View.VISIBLE);
                findViewById(R.id.fab).setVisibility(View.VISIBLE);
            }

        }

我的布局文件是

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    xmlns:fab="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/webview_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        android:visibility="invisible"
        tools:context=".universalwebview.MainActivity">

        <WebView
            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scrollbars="none" />
    </FrameLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="right|bottom"
        android:layout_marginBottom="70dp"
        android:layout_marginRight="10dp"
        android:clickable="true"
        android:src="@drawable/ic_action_share"
        app:backgroundTint="#00a478"
        app:borderWidth="0dp"
        app:elevation="6dp"
        app:fabSize="normal"
        app:pressedTranslationZ="12dp"
        app:rippleColor="#00a470" />
    <LinearLayout
        android:id="@+id/toolbar_footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="#333"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/home"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="10dp"
            android:src="@drawable/ic_action_home"
            android:tint="@color/tintcolor" />

        <ImageView
            android:id="@+id/search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="10dp"
            android:src="@drawable/ic_action_search"
            android:tint="@color/tintcolor" />

        <ImageView
            android:id="@+id/uploadvideo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="10dp"
            android:src="@drawable/ic_action_add"
            android:tint="#00a478" />

        <ImageView
            android:id="@+id/profile"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="10dp"
            android:src="@drawable/ic_action_profile"
            android:tint="@color/tintcolor" />


        <ImageView
            android:id="@+id/settings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?attr/selectableItemBackground"
            android:clickable="true"
            android:padding="10dp"
            android:src="@drawable/ic_action_settings"
            android:tint="@color/tintcolor" />

    </LinearLayout>

    <ImageView
        android:id="@+id/image_splash"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:visibility="visible"
        android:src="@drawable/splash" />
</RelativeLayout>
android android-layout android-linearlayout android-toolbar
1个回答
0
投票

隐藏工具栏你必须把这条线。 getSupportActionBar().hide();

因此,首先检查是否有网址然后将此行放入if block if(url.contains(“your text”){ getSupportActionBar().hide(); }

热门问题
推荐问题
最新问题