當前位置: 首頁>>代碼示例>>Java>>正文


Java WebView.getSettings方法代碼示例

本文整理匯總了Java中android.webkit.WebView.getSettings方法的典型用法代碼示例。如果您正苦於以下問題:Java WebView.getSettings方法的具體用法?Java WebView.getSettings怎麽用?Java WebView.getSettings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.webkit.WebView的用法示例。


在下文中一共展示了WebView.getSettings方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initWebViewSettings

import android.webkit.WebView; //導入方法依賴的package包/類
public static void initWebViewSettings(WebView webView) {
    WebSettings settings = webView.getSettings();
    //這個單位是SP
    settings.setDefaultFontSize(15);

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

    settings.setUseWideViewPort(false);  //將圖片調整到適合webview的大小

    settings.setSupportZoom(true);  //支持縮放

    settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);//無論是否有網絡,隻要本地有緩存,都使用緩存。本地沒有緩存時才從網絡上獲取。 這裏的WebView主要是用來加載圖片和解析Html文本

    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //支持內容重新布局

    webView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //使超鏈接失效
            return true;
        }
    });

}
 
開發者ID:FallenCrood,項目名稱:Review-,代碼行數:25,代碼來源:WebViewHelper.java

示例2: initWebViewSettings

import android.webkit.WebView; //導入方法依賴的package包/類
/**
 * @param webView
 */
@SuppressLint("SetJavaScriptEnabled")
public static void initWebViewSettings(WebView webView) {
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    webSettings.setDefaultFontSize(15);
    //設置緩存
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);

    webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webSettings.setAppCacheEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCachePath(AppConfig.WEB_CACHE_PATH);
}
 
開發者ID:z-chu,項目名稱:FriendBook,代碼行數:21,代碼來源:AppRouter.java

示例3: onCreate

import android.webkit.WebView; //導入方法依賴的package包/類
@SuppressLint("SetJavaScriptEnabled")
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);
    mainIntent = getIntent();
    manager = getSupportFragmentManager();

    myBrowser = (WebView) findViewById(R.id.webView);
    webSettings = myBrowser.getSettings();
    webSettings.setJavaScriptEnabled(true);

    MyDeviceAPI = Build.VERSION.SDK_INT;
    // Calling async task to get display content
    new RenderView().execute();
}
 
開發者ID:theapache64,項目名稱:CCAvenue-Android-Example-Advanced,代碼行數:18,代碼來源:WebViewActivity.java

示例4: CustomWebViewClient

import android.webkit.WebView; //導入方法依賴的package包/類
/**
 * Constructor.
 * @param activity Activity to manage intents.
 * @param wv <code>WebView</code> where web site will be shown.
 * @param url URL address where it is hosted.
 * @param urlBase URL main address.
 * @param initialScale Initial zoom (0 is default).
 */
@SuppressLint("SetJavaScriptEnabled")
public CustomWebViewClient(Activity activity, WebView wv, String url, String urlBase, UrlCache urlCache, int initialScale) {
    this.activity = activity;
    this.wv = wv;
    this.url = url;
    this.urlBase = urlBase;
    this.initialScale = initialScale;
    this.urlCache = urlCache;

    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true); // We enable Javascript by default, due to it is needed by lots of websites

    wv.loadUrl(url);
    wv.setInitialScale(initialScale);
}
 
開發者ID:GabrielMorenoIbarra,項目名稱:BackendDrivenMenu,代碼行數:24,代碼來源:CustomWebViewClient.java

示例5: SourceEditor

import android.webkit.WebView; //導入方法依賴的package包/類
/**
 * Create source editor using given web view
 *
 * @param view
 */
@SuppressLint("AddJavascriptInterface")
public SourceEditor(final WebView view) {
    WebSettings settings = view.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);
    try {
        int version = Build.VERSION.SDK_INT;
        if (version >= 11) {
            // 這個方法在API level 11 以上才可以調用,不然會發生異常
            settings.setDisplayZoomControls(false);
        }
    } catch (NumberFormatException e) {

    }
    settings.setUseWideViewPort(true);
    view.addJavascriptInterface(SourceEditor.this, "SourceEditor");
    this.view = view;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:24,代碼來源:SourceEditor.java

示例6: onCreate

import android.webkit.WebView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.login_webview_activity);

    WebView webView = findViewById(R.id.webview);
    WebSettings webSettings = webView.getSettings();
    webView.setWebViewClient(new WebViewClient());
    webSettings.setJavaScriptEnabled(true);

    String url = getIntent().getStringExtra("url");
    if (url == null) {
        url = "file:///android_res/raw/sample_form.html";
    }
    if (DEBUG) Log.d(TAG, "Clearing WebView data");
    webView.clearHistory();
    webView.clearFormData();
    webView.clearCache(true);
    Log.i(TAG, "Loading URL " + url);
    webView.loadUrl(url);
}
 
開發者ID:googlesamples,項目名稱:android-AutofillFramework,代碼行數:23,代碼來源:WebViewSignInActivity.java

示例7: onCreate

import android.webkit.WebView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    setContentView(R.layout.activity_web);
    name = getIntent().getExtras().getString(Common.WEBVIEW_EXTRA_NAME);
    url = getIntent().getExtras().getString(Common.WEBVIEW_EXTRA_URL);
    color = getIntent().getExtras().getInt(Common.WEBVIEW_EXTRA_COLOR);
    needsLogin = getIntent().getExtras().getBoolean(Common.WEBVIEW_EXTRA_NLOGIN);
    //Action bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().setNavigationBarColor(color);
        getWindow().setStatusBarColor(color);
    }
    app = (App) getApplication();

    TextView title = (TextView) findViewById(R.id.toolbar_title);
    title.setText(name);

    progress = (ProgressBar) findViewById(R.id.web_progressBar);
    webView = (WebView) findViewById(R.id.webView);

    if (savedInstanceState != null) {
        progress.setVisibility(View.INVISIBLE);
        webView.setVisibility(View.VISIBLE);
        webView.restoreState(savedInstanceState);
    }
    else {
        progress.setVisibility(View.VISIBLE);
        webView.setWebViewClient(new WebViewClient());
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setUserAgentString("IEMobile");
        startControllers();
    }

}
 
開發者ID:Onelio,項目名稱:ConnectU,代碼行數:41,代碼來源:WebActivity.java

示例8: getUserAgent

import android.webkit.WebView; //導入方法依賴的package包/類
public static String getUserAgent(Context context) {
    String userAgent = null;
    WebView webView = new WebView(context);
    WebSettings settings = webView.getSettings();
    if (settings != null) {
        userAgent = settings.getUserAgentString();
    }
    return userAgent;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:StrUtils.java

示例9: createWebView

import android.webkit.WebView; //導入方法依賴的package包/類
private void createWebView() {
    myWebView = (WebView) findViewById(R.id.webview);
    myWebView.clearCache(true);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebViewClient = new MyWebViewClient();
    myWebView.setWebViewClient(mWebViewClient);
    myWebView.setWebChromeClient(new MyWebChromeClient());
    // Start initial page load so WebView finishes loading proxy settings.
    // Actual load of mUrl is initiated by MyWebViewClient.
}
 
開發者ID:jsparber,項目名稱:CaptivePortalAutologin,代碼行數:12,代碼來源:CaptivePortalLoginActivity.java

示例10: AccountCreationWebview

import android.webkit.WebView; //導入方法依賴的package包/類
@SuppressLint("SetJavaScriptEnabled")
public AccountCreationWebview(BasePrefsWizard aParent, String url, OnAccountCreationDoneListener l){
    parent = aParent;
    creationListener = l;
    webCreationPage = url;
    
    settingsContainer = (ViewGroup) parent.findViewById(R.id.settings_container);
    validationBar = (ViewGroup) parent.findViewById(R.id.validation_bar);
    
    ViewGroup globalContainer = (ViewGroup) settingsContainer.getParent();
    
    parent.getLayoutInflater().inflate(R.layout.wizard_account_creation_webview, globalContainer);
    
    webView = (WebView) globalContainer.findViewById(R.id.webview);
    loadingProgressBar = (ProgressBar) globalContainer.findViewById(R.id.webview_progress);
    
    WebSettings webSettings = webView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(false);
    webSettings.setCacheMode(WebSettings.LOAD_NORMAL);
    webSettings.setNeedInitialFocus(true);
    webView.addJavascriptInterface(new JSInterface(), "CSipSimpleWizard");
    
    // Adds Progress bar Support
    webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            if(progress < 100) {
                loadingProgressBar.setVisibility(View.VISIBLE);
                loadingProgressBar.setProgress(progress); 
            }else {
                loadingProgressBar.setVisibility(View.GONE);
            }
        }
    });
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:38,代碼來源:AccountCreationWebview.java

示例11: onCreate

import android.webkit.WebView; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    listeners = new ArrayList<>();
    progressListeners = new ArrayList<>();
    webView = new WebView(this);
    webView.setWebViewClient(new WebClient(this));
    webView.setWebChromeClient(new ChromeClient(this));
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setLoadsImagesAutomatically(false);
    webSettings.setUserAgentString("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0");
}
 
開發者ID:TheAndroidMaster,項目名稱:Blackboard,代碼行數:15,代碼來源:Blackboard.java

示例12: onViewCreated

import android.webkit.WebView; //導入方法依賴的package包/類
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    WebView webView = (WebView) view.findViewById(R.id.webView);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        settings.setAllowUniversalAccessFromFileURLs(true);
    }
    settings.setBuiltInZoomControls(true);
    //webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl(GOOGLE_DRIVE_LINK2 + WEB_PATH_TO_PDF);
}
 
開發者ID:WorldBank-Transport,項目名稱:RoadLab-Pro,代碼行數:15,代碼來源:PdfViewFragment.java

示例13: onCreate

import android.webkit.WebView; //導入方法依賴的package包/類
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_webview);

  myWebView = (WebView) findViewById(R.id.webview);
  WebSettings webSettings = myWebView.getSettings();
  webSettings.setJavaScriptEnabled(true);
  webSettings.setDomStorageEnabled(true);
  myWebView.addJavascriptInterface(new WebAppInterface(WebviewActivity.this), "Android");
  myWebView.setWebViewClient(new MyWebViewClient());

  // hosted site url
  myWebView.loadUrl("http://cicradon.000webhostapp.com/");
}
 
開發者ID:Radon-MSIT,項目名稱:hackCIC,代碼行數:15,代碼來源:WebviewActivity.java

示例14: init

import android.webkit.WebView; //導入方法依賴的package包/類
/**
 * 係統初始化
 * 
 * @param context
 */
public static void init(Context context)
{
	if (CDK.getInstance().getContext() != null)
	{
		return;
	}

	Context application = context.getApplicationContext();
	
	// 用於獲取瀏覽器代理
	WebView webview = new WebView(context);
	webview.layout(0, 0, 0, 0);
	WebSettings webSettings = webview.getSettings();
	
	ApplicationInfo applicationInfo = context.getApplicationInfo();
	
	VersionInfo versionInfo = ManifestTools.getVersionInfo(application);
	String userAgent = webSettings.getUserAgentString();
	
	// Structure the CDKContext.
	CDKContext cdkContext = new CDKContext(application.getPackageName());
	//clientInfo.setAppicon(R.drawable.ic_launcher);
	cdkContext.setAppicon(applicationInfo.icon);
	cdkContext.setAppname(ManifestTools.getApplicationLable(application));
	cdkContext.setDeviceType(CDKConfig.Device.PHONE);
	cdkContext.setAlias(android.os.Build.MODEL);
	cdkContext.setAndroidSdkVersion(android.os.Build.VERSION.SDK_INT);
	cdkContext.setMac(DeviceInfoManager.getMacAddress(application));
	
	// Webkit user-agent
	cdkContext.setUserAgent(userAgent);
	
	if (versionInfo != null)
	{
		cdkContext.setAppVersionCode(versionInfo.getVersionCode());
		cdkContext.setAppVersionName(versionInfo.getVersionName());
	}
	
	// FIXME: Take attention...
	cdkContext.addFlags(CDKContext.FLAG_DEBUG | CDKContext.FLAG_RELEASE);
	// cdkContext.addFlags(CDKContext.FLAG_DEBUG);
	
	// TODO: 廣告
	CDKConfig config = new CDKConfig.Builder(application)
		.cdkContext(cdkContext)
		.hasAdBanner(false)		// 顯示積分Banner
		.hasAdPointsWall(true)	// 顯示積分牆
		.build();
	
	CDK.getInstance().init(config);
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:57,代碼來源:Global.java

示例15: onCreate

import android.webkit.WebView; //導入方法依賴的package包/類
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view);
        Intent in = getIntent();
        web = in.getStringExtra("web");
        if (TextUtils.isEmpty(web)) {
            Toast.makeText(this, "地址為空", Toast.LENGTH_SHORT).show();
        } else {
            WebView webView = (WebView) findViewById(R.id.web);
            webView.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    return false;// 返回false
                }
            });

            WebSettings webSettings = webView.getSettings();
            // 讓WebView能夠執行javaScript
            webSettings.setJavaScriptEnabled(true);
            // 讓JavaScript可以自動打開windows
            webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
//        // 設置緩存
//        webSettings.setAppCacheEnabled(true);
//        // 設置緩存模式,一共有四種模式
//        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
//        // 設置緩存路徑
//        webSettings.setAppCachePath("/storage/emulated/0/Android/data/com.easyar.buddha/files");
            // 支持縮放(適配到當前屏幕)
            webSettings.setSupportZoom(true);
            // 將圖片調整到合適的大小
            webSettings.setUseWideViewPort(true);
            // 支持內容重新布局,一共有四種方式
            // 默認的是NARROW_COLUMNS
            webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
            // 設置可以被顯示的屏幕控製
            webSettings.setDisplayZoomControls(true);
            // 設置默認字體大小
            webSettings.setDefaultFontSize(12);
            webView.loadUrl(web);
        }
    }
 
開發者ID:pili-engineering,項目名稱:PLDroidShortVideo,代碼行數:43,代碼來源:WebViewActivity.java


注:本文中的android.webkit.WebView.getSettings方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。