Webview的各种属性

package com.example.gaowen38.view.activity;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.example.gaowen38.Base.MyBaseActivity;
import com.example.gaowen38.R;

import butterknife.BindView;
import butterknife.ButterKnife;
/**
 *
 * @作者 红鼻子小黑
 * @姓名 赵鑫乐
 * @创建日期 2019/3/25 11:10
 * h5
 */
public class
BusinessDistrictH5Activity extends MyBaseActivity {

    @BindView(R.id.web_s)
    WebView webS;
    private String shangquanh5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_business_district_h5);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        shangquanh5 = intent.getStringExtra("shangquanh5");
        WebSettings settings = webS.getSettings();

// 支持javascript
        settings.setJavaScriptEnabled(true);

// 支持使用localStorage(H5页面的支持)
        settings.setDomStorageEnabled(true);

// 支持数据库
        settings.setDatabaseEnabled(true);

// 支持缓存
        settings.setAppCacheEnabled(true);
        String appCaceDir = getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
        settings.setAppCachePath(appCaceDir);

// 设置可以支持缩放
        settings.setUseWideViewPort(true);

// 扩大比例的缩放
        settings.setSupportZoom(true);

        settings.setBuiltInZoomControls(true);

// 隐藏缩放按钮
        settings.setDisplayZoomControls(false);

// 自适应屏幕
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setLoadWithOverviewMode(true);

// 隐藏滚动条
        webS.setHorizontalScrollBarEnabled(false);
        webS.setVerticalScrollBarEnabled(false);

// 进度显示及隐藏
        webS.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress >= 99) {
//                    pv.setVisibility(View.INVISIBLE);
                } else {
//                    pv.setVisibility(View.VISIBLE);
                }
            }
        });

// 处理网页内的连接(自身打开)
        webS.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(request.getUrl().toString());
                return true;
            }
        });

        settings.setDomStorageEnabled(true);
        webS.loadUrl(shangquanh5);

        // 使用返回键的方式防止网页重定向
        webS.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    if (keyCode == KeyEvent.KEYCODE_BACK && webS.canGoBack()) {
                        webS.goBack();
                        return true;
                    }
                }
                return false;
            }
        });

    }

//    public void fullScreen(){
//        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
//            mCustomScreenLinearLayout.scrollTo(0, 0);
//            mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//            mUrlBarAutoShowManager.flag = false;
//            mFixedTitlebarContainer.setVisibility(View.GONE);
//            showFixTitle(false);
//            mBottomNavigation.hideBottomNav();
//            mBottomFrameLayout.setVisibility(View.GONE);
//        }else
//            mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//            mUrlBarAutoShowManager.flag = true;
//            mFixedTitlebarContainer.setVisibility(View.VISIBLE);
//            hideFixTitle(false);
//            mBottomNavigation.showBottomNav();
//            mBottomFrameLayout.setVisibility(View.VISIBLE);
//        }
//    }

}

你可能感兴趣的:(android,webview,java)