當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。