当前位置: 首页>>代码示例>>Java>>正文


Java WebView.setLayerType方法代码示例

本文整理汇总了Java中android.webkit.WebView.setLayerType方法的典型用法代码示例。如果您正苦于以下问题:Java WebView.setLayerType方法的具体用法?Java WebView.setLayerType怎么用?Java WebView.setLayerType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.webkit.WebView的用法示例。


在下文中一共展示了WebView.setLayerType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);

    getSupportActionBar().setTitle(getString(R.string.about));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    progressBar = (ProgressBar) findViewById(R.id.progress);
    progressBar.getIndeterminateDrawable()
            .setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
    info_web = (WebView) findViewById(R.id.webview_company_info);
    info_web.setBackgroundColor(Color.TRANSPARENT);
    info_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    info_web.setWebViewClient(new myWebClient());
    info_web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    info_web.getSettings().setJavaScriptEnabled(true);
    info_web.getSettings().setDefaultFontSize((int) getResources().getDimension(R.dimen.about_text_size));

    String infoText = getString(R.string.company_info_web);
    info_web.loadDataWithBaseURL("file:///android_asset/fonts/", getWebViewText(infoText), "text/html", "utf-8", null);

}
 
开发者ID:fekracomputers,项目名称:MuslimMateAndroid,代码行数:24,代码来源:AboutActivity.java

示例2: onCreate

import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);

    getSupportActionBar().setTitle(getString(R.string.about));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    progressBar = (ProgressBar) findViewById(R.id.progress);
    progressBar.getIndeterminateDrawable()
            .setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
    info_web = (WebView) findViewById(R.id.webview_company_info);
    info_web.setBackgroundColor(Color.TRANSPARENT);
    info_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    info_web.setWebViewClient(new myWebClient());
    info_web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    info_web.getSettings().setJavaScriptEnabled(true);
    String infoText = getString(R.string.company_info_web);
    info_web.loadDataWithBaseURL("file:///android_asset/fonts/", getWebViewText(infoText), "text/html", "utf-8", null);

}
 
开发者ID:fekracomputers,项目名称:QuranAndroid,代码行数:22,代码来源:AboutActivity.java

示例3: onCreateDialog

import android.webkit.WebView; //导入方法依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final WebView webView = (WebView) LayoutInflater.from(getActivity()).inflate(R.layout.about_dialog, null);
    final String lang = Locale.getDefault().getLanguage();
    String uri = "file:///android_asset/about.html";
    try {
        // Load language-specific version of the about page if available.
        final List<String> assets = Arrays.asList(getResources().getAssets().list(""));
        if (assets.contains(String.format("about-%s.html", lang))) {
            uri = String.format("file:///android_asset/about-%s.html", lang);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        // Getting Chromium crashes on certain KitKat devices. Might be caused by hardware acceleration
        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    webView.loadUrl(uri);
    webView.setBackgroundColor(Color.TRANSPARENT);
    return new AlertDialog.Builder(getActivity())
            .setTitle(R.string.about)
            .setView(webView)
            .setPositiveButton(R.string.ok, null)
            .create();
}
 
开发者ID:steevp,项目名称:UpdogFarmer,代码行数:28,代码来源:AboutDialog.java

示例4: initView

import android.webkit.WebView; //导入方法依赖的package包/类
@SuppressLint("NewApi")
private void initView() {
    webView = (WebView) findViewById(R.id.webView);
    setTitle("关于(V"+getVersionName(this)+")");

    settings = webView.getSettings();
    settings.setJavaScriptEnabled(true); //如果访问的页面中有Javascript,则WebView必须设置支持Javascript
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setSupportZoom(true); //支持缩放
    settings.setBuiltInZoomControls(true); //支持手势缩放
    settings.setDisplayZoomControls(false); //是否显示缩放按钮

    // >= 19(SDK4.4)启动硬件加速,否则启动软件加速
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        settings.setLoadsImagesAutomatically(true); //支持自动加载图片
    } else {
        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        settings.setLoadsImagesAutomatically(false);
    }

    settings.setUseWideViewPort(true); //将图片调整到适合WebView的大小
    settings.setLoadWithOverviewMode(true); //自适应屏幕
    settings.setDomStorageEnabled(true);
    settings.setSaveFormData(true);
    settings.setSupportMultipleWindows(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT); //优先使用缓存

    webView.setHorizontalScrollbarOverlay(true);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setOverScrollMode(View.OVER_SCROLL_NEVER); // 取消WebView中滚动或拖动到顶部、底部时的阴影
    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); // 取消滚动条白边效果
    webView.requestFocus();

    webView.loadUrl("file:///android_asset/about.html");
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:45,代码来源:AboutActivity.java

示例5: settings

import android.webkit.WebView; //导入方法依赖的package包/类
private void settings(WebView webView) {


        mWebSettings = webView.getSettings();
        mWebSettings.setJavaScriptEnabled(true);
        mWebSettings.setSupportZoom(true);
        mWebSettings.setBuiltInZoomControls(false);
        mWebSettings.setSavePassword(false);
        if (AgentWebUtils.checkNetwork(webView.getContext())) {
            //根据cache-control获取数据。
            mWebSettings.setCacheMode(android.webkit.WebSettings.LOAD_DEFAULT);
        } else {
            //没网,则从本地获取,即离线加载
            mWebSettings.setCacheMode(android.webkit.WebSettings.LOAD_CACHE_ELSE_NETWORK);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //适配5.0不允许http和https混合使用情况
            mWebSettings.setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
            webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }

        mWebSettings.setTextZoom(100);
        mWebSettings.setDatabaseEnabled(true);
        mWebSettings.setAppCacheEnabled(true);
        mWebSettings.setLoadsImagesAutomatically(true);
        mWebSettings.setSupportMultipleWindows(false);
        mWebSettings.setBlockNetworkImage(false);//是否阻塞加载网络图片  协议http or https
        mWebSettings.setAllowFileAccess(true); //允许加载本地文件html  file协议
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            mWebSettings.setAllowFileAccessFromFileURLs(false); //通过 file url 加载的 Javascript 读取其他的本地文件 .建议关闭
            mWebSettings.setAllowUniversalAccessFromFileURLs(false);//允许通过 file url 加载的 Javascript 可以访问其他的源,包括其他的文件和 http,https 等其他的源
        }
        mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

            mWebSettings.setLayoutAlgorithm(android.webkit.WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        } else {
            mWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        }
        mWebSettings.setLoadWithOverviewMode(true);
        mWebSettings.setUseWideViewPort(true);
        mWebSettings.setDomStorageEnabled(true);
        mWebSettings.setNeedInitialFocus(true);
        mWebSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
        mWebSettings.setDefaultFontSize(16);
        mWebSettings.setMinimumFontSize(12);//设置 WebView 支持的最小字体大小,默认为 8
        mWebSettings.setGeolocationEnabled(true);
        //
        String dir = AgentWebConfig.getCachePath(webView.getContext());

        LogUtils.i(TAG, "dir:" + dir + "   appcache:" + AgentWebConfig.getCachePath(webView.getContext()));
        //设置数据库路径  api19 已经废弃,这里只针对 webkit 起作用
        mWebSettings.setGeolocationDatabasePath(dir);
        mWebSettings.setDatabasePath(dir);
        mWebSettings.setAppCachePath(dir);

        //缓存文件最大值
        mWebSettings.setAppCacheMaxSize(Long.MAX_VALUE);

        mWebSettings.setUserAgentString(getWebSettings()
                .getUserAgentString()
                .concat(USERAGENT_AGENTWEB)
                .concat(USERAGENT_UC)
        );


        LogUtils.i(TAG,"UserAgentString : "+mWebSettings.getUserAgentString());


    }
 
开发者ID:Justson,项目名称:AgentWeb,代码行数:76,代码来源:WebDefaultSettingsManager.java

示例6: onCreate

import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_moodle);
    Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    webView = (WebView) findViewById(R.id.web_moodle);
    webSettings = webView.getSettings();
    webSettings.setAppCacheEnabled(true);
    //webSettings.setCacheMode(webSettings.LOAD_CACHE_ELSE_NETWORK);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setAllowFileAccess(true);
    webView.setVerticalScrollBarEnabled(false);
    webView.getSettings().setDomStorageEnabled(true);
    webView.setHorizontalScrollBarEnabled(false);
    CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
    CookieManager.getInstance().setAcceptCookie(true);
    //final SharedPreferences profile = getSharedPreferences("userdata", 0);
    webView.setWebViewClient(new PQClient());
    webView.setWebChromeClient(new PQChromeClient());
    //if SDK version is greater of 19 then activate hardware acceleration otherwise activate software acceleration
    if (Build.VERSION.SDK_INT >= 19) {
        webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    else if(Build.VERSION.SDK_INT >=11 && Build.VERSION.SDK_INT < 19) {
        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    webView.loadUrl("http://moodle.coep.org.in/moodle/login/index.php");
    webView.setDownloadListener(new DownloadListener() {

        @Override
        public void onDownloadStart(String url, String userAgent,
                                    String contentDisposition, String mimetype,
                                    long contentLength) {
            try {
                DownloadManager.Request request = new DownloadManager.Request(
                        Uri.parse(url));
            /* Let's have some Cookies !!!*/
                String cookies = CookieManager.getInstance().getCookie(url);
                request.addRequestHeader("cookie", cookies);
                //Yummy !!
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
                final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
                DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                dm.enqueue(request);
                makeText(getApplicationContext(), "Downloading File", //To notify the Client that the file is being downloaded
                        Toast.LENGTH_LONG).show();
            }
            catch(SecurityException e)
            {
                Toast.makeText(getApplicationContext(),"Please grant the storage permission !",Toast.LENGTH_LONG).show();
            }

        }
    });
}
 
开发者ID:ashutoshbsathe,项目名称:COEP-Moodle-via-Webview,代码行数:62,代码来源:Moodle.java

示例7: onCreateView

import android.webkit.WebView; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_azkar_view, container, false);

    zekerContainer = (WebView) rootView.findViewById(R.id.webView);
    zekerContainer.getSettings().setTextSize(WebSettings.TextSize.NORMAL);
    count = (ImageView) rootView.findViewById(R.id.time);
    share = (ImageView) rootView.findViewById(R.id.share);
    countDown = (TextView) rootView.findViewById(R.id.countDown);

    count.setOnClickListener(this);
    share.setOnClickListener(this);

    countDown.setText(NumbersLocal.convertNumberType(getContext() , String.valueOf(getArguments().getInt(REPEAT))));
    if (getArguments().getInt(REPEAT) == 1) {
        count.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        count.setImageResource(R.drawable.ic_move_next);
    }
    content = (getArguments().getString(CONTENT));
    fadl = (getArguments().getString(FADL)) == null ||
            (getArguments().getString(FADL)).trim().equals("")
            ? "الراوى غير متوفر" : (getArguments().getString(FADL)).trim();
    type = getArguments().getString(TYPE);

    if (Build.VERSION.SDK_INT >= 19) {
        // chromium, enable hardware acceleration
        zekerContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } else {
        // older android version, disable hardware acceleration
        zekerContainer.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    zekerContainer.setBackgroundColor(Color.TRANSPARENT);

    zekerContainer.loadDataWithBaseURL("file:///android_asset/fonts/",
            String.format("<head> <style>@font-face" +
                            " {font-family: 'font' ;src: url('simple.otf');}div" +
                            " { font-family: 'font';  word-spacing: 1px;} </style></head>" +
                            "<body align='justify'" +
                            " dir='rtl' style='line-height:1.4em ; font-size:x-large'> <div>" +
                            " <span style='color:#3E686A'>%s</span> <br><font size='5.5'>%s</font> </div> </body>"
                    , fadl, content), "text/html", "utf8", "");
    return rootView;
}
 
开发者ID:fekracomputers,项目名称:MuslimMateAndroid,代码行数:46,代码来源:AzkarActivity.java


注:本文中的android.webkit.WebView.setLayerType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。