本文整理匯總了Java中android.webkit.WebView類的典型用法代碼示例。如果您正苦於以下問題:Java WebView類的具體用法?Java WebView怎麽用?Java WebView使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
WebView類屬於android.webkit包,在下文中一共展示了WebView類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onPageFinished
import android.webkit.WebView; //導入依賴的package包/類
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().flush();
} else {
CookieSyncManager.getInstance().sync();
}
// https://issues.apache.org/jira/browse/CB-11248
view.clearFocus();
view.requestFocus();
try {
JSONObject obj = new JSONObject();
obj.put("type", LOAD_STOP_EVENT);
obj.put("url", url);
sendUpdate(obj, true);
} catch (JSONException ex) {
LOG.d(LOG_TAG, "Should never happen");
}
}
示例2: onCreate
import android.webkit.WebView; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webview);
String url = "file:///android_asset/sample.html";
webView.getSettings().setJavaScriptEnabled(true);
webChromeClient = new FileChooserWebChromeClient();
webView.setWebChromeClient(webChromeClient);
webView.loadUrl(url);
WebView.setWebContentsDebuggingEnabled(true);
}
示例3: findScrollableViewInternal
import android.webkit.WebView; //導入依賴的package包/類
private View findScrollableViewInternal(View content, boolean selfable) {
View scrollableView = null;
Queue<View> views = new LinkedBlockingQueue<>(Collections.singletonList(content));
while (!views.isEmpty() && scrollableView == null) {
View view = views.poll();
if (view != null) {
if ((selfable || view != content) && (view instanceof AbsListView
|| view instanceof ScrollView
|| view instanceof ScrollingView
|| view instanceof NestedScrollingChild
|| view instanceof NestedScrollingParent
|| view instanceof WebView
|| view instanceof ViewPager)) {
scrollableView = view;
} else if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
for (int j = 0; j < group.getChildCount(); j++) {
views.add(group.getChildAt(j));
}
}
}
}
return scrollableView;
}
示例4: init
import android.webkit.WebView; //導入依賴的package包/類
private void init(){
LinearLayout layout = (LinearLayout) findViewById(R.id.Download_layout);
layout.setVisibility(View.GONE);
Intent intent = getIntent();
body = intent.getStringExtra("body");
title = intent.getStringExtra("title");
contentView = (WebView) findViewById(R.id.content_webview);
contentView.setHorizontalScrollBarEnabled(false);//水平不顯示
contentView.setVerticalScrollBarEnabled(false); //垂直不顯示
contentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return (event.getAction() == MotionEvent.ACTION_MOVE);
}
});
contentView.setWebViewClient(new WebViewClient());
topImage = (ImageView) findViewById(R.id.top_image);
topTitle = (TextView) findViewById(R.id.top_titlt);
topSource = (TextView) findViewById(R.id.top_source);
}
示例5: shouldOverrideUrlLoading
import android.webkit.WebView; //導入依賴的package包/類
/**
* Give the host application a chance to take over the control when a new url
* is about to be loaded in the current WebView.
*
* @param view The WebView that is initiating the callback.
* @param url The url to be loaded.
* @return true to override, false for default behavior
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
boolean shouldOverrideUrlLoading(WebView view, String url) {
// Give plugins the chance to handle the url
if (this.appView.pluginManager.onOverrideUrlLoading(url)) {
// Do nothing other than what the plugins wanted.
// If any returned true, then the request was handled.
return true;
}
else if(url.startsWith("file://") | url.startsWith("data:"))
{
//This directory on WebKit/Blink based webviews contains SQLite databases!
//DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
return url.contains("app_webview");
}
else if (appView.getWhitelist().isUrlWhiteListed(url)) {
// Allow internal navigation
return false;
}
else if (appView.getExternalWhitelist().isUrlWhiteListed(url))
{
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setComponent(null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
intent.setSelector(null);
}
this.cordova.getActivity().startActivity(intent);
return true;
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading url " + url, e);
}
}
// Intercept the request and do nothing with it -- block it
return true;
}
示例6: onCreate
import android.webkit.WebView; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_story_webview);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final Item item = (Item) getIntent().getSerializableExtra("item");
WebView webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
setContentView(webView);
webView.loadUrl(item.getUrl());
}
示例7: getAllMethod
import android.webkit.WebView; //導入依賴的package包/類
/**
* 獲取框架api類中所有符合要求的api
*
* @param injectedCls
* @return
* @throws Exception
*/
private static HashMap<String, Method> getAllMethod(Class injectedCls) throws Exception {
HashMap<String, Method> mMethodsMap = new HashMap<>();
Method[] methods = injectedCls.getDeclaredMethods();
for (Method method : methods) {
String name;
if (method.getModifiers() != (Modifier.PUBLIC | Modifier.STATIC) || (name = method.getName()) == null) {
continue;
}
Class[] parameters = method.getParameterTypes();
if (null != parameters && parameters.length == 4) {
if (parameters[1] == WebView.class && parameters[2] == JSONObject.class && parameters[3] == Callback.class) {
mMethodsMap.put(name, method);
}
}
}
return mMethodsMap;
}
示例8: onPageStarted
import android.webkit.WebView; //導入依賴的package包/類
/**
* Notify the host application that a page has started loading.
* This method is called once for each main frame load so a page with iframes or framesets will call onPageStarted
* one time for the main frame. This also means that onPageStarted will not be called when the contents of an
* embedded frame changes, i.e. clicking a link whose target is an iframe.
*
* @param view The webview initiating the callback.
* @param url The url of the page.
*/
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
isCurrentlyLoading = true;
LOG.d(TAG, "onPageStarted(" + url + ")");
// Flush stale messages.
this.appView.bridge.reset(url);
// Broadcast message that page has loaded
this.appView.postMessage("onPageStarted", url);
// Notify all plugins of the navigation, so they can clean up if necessary.
if (this.appView.pluginManager != null) {
this.appView.pluginManager.onReset();
}
}
示例9: flingCompat
import android.webkit.WebView; //導入依賴的package包/類
public static void flingCompat(View view, int velocityY) {
if (view instanceof ScrollView) {
((ScrollView) view).fling(velocityY);
} else if (view instanceof WebView) {
((WebView) view).flingScroll(0, velocityY);
} else if (view instanceof RecyclerView) {
((RecyclerView) view).fling(0, velocityY);
} else if (view instanceof NestedScrollView) {
((NestedScrollView) view).fling(velocityY);
} else if (view instanceof AbsListView) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
((AbsListView) view).fling(velocityY);
} else {
SRReflectUtil.compatOlderAbsListViewFling((AbsListView) view, velocityY);
}
}
}
示例10: fetchArticleBody
import android.webkit.WebView; //導入依賴的package包/類
private void fetchArticleBody() {
setBusy(true);
AnnouncementModels.fetchArticleBody(articleID, new ModelListener<String>() {
@Override
public void onData(String result, String message) {
setBusy(false);
if (result == null) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
} else {
WebView wb = (WebView) findViewById(R.id.webViewforArticle);
wb.loadData(result, "text/html;charset=utf-8", null);
wb.getSettings().setLoadWithOverviewMode(true);
wb.getSettings().setUseWideViewPort(true);
}
}
});
}
示例11: initWebView
import android.webkit.WebView; //導入依賴的package包/類
private void initWebView() {
mContentWebView.getSettings().setUseWideViewPort(false);
mContentWebView.getSettings().setLoadWithOverviewMode(true);
mContentWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mContentWebView.setWebChromeClient(new WebChromeClient());
mContentWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
FragmentFactory.PageType pageType = FragmentFactory.getPageTypeByUrl(url);
if (mListener != null && pageType == FragmentFactory.PageType.VIEW_IMAGE) {
mListener.openPage(url, getString(R.string.view_image));
return true;
}
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
});
mContentWebView.getSettings().setJavaScriptEnabled(true);
}
示例12: onReceivedClientCertRequest
import android.webkit.WebView; //導入依賴的package包/類
/**
* On received client cert request.
* The method forwards the request to any running plugins before using the default implementation.
*
* @param view
* @param request
*/
@Override
@TargetApi(21)
public void onReceivedClientCertRequest (WebView view, ClientCertRequest request)
{
// Check if there is some plugin which can resolve this certificate request
PluginManager pluginManager = this.parentEngine.pluginManager;
if (pluginManager != null && pluginManager.onReceivedClientCertRequest(null, new CordovaClientCertRequest(request))) {
parentEngine.client.clearLoadTimeoutTimer();
return;
}
// By default pass to WebViewClient
super.onReceivedClientCertRequest(view, request);
}
示例13: onCreateDialog
import android.webkit.WebView; //導入依賴的package包/類
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
WebView webView = new WebView(getActivity());
webView.loadUrl("file:///android_asset/licenses.html");
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.about_licenses)
.setView(webView)
.setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
}
)
.create();
}
示例14: onJsPrompt
import android.webkit.WebView; //導入依賴的package包/類
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
Log.i(TAG,"onJsPrompt:"+url+" message:"+message+" d:"+defaultValue+" ");
if (mJsCallJavas != null && JsCallJava.isSafeWebViewCallMsg(message)) {
JSONObject jsonObject = JsCallJava.getMsgJSONObject(message);
String interfacedName = JsCallJava.getInterfacedName(jsonObject);
if (interfacedName != null) {
JsCallJava jsCallJava = mJsCallJavas.get(interfacedName);
if (jsCallJava != null) {
result.confirm(jsCallJava.call(view, jsonObject));
}
}
return true;
} else {
return false;
}
}
示例15: onCreate
import android.webkit.WebView; //導入依賴的package包/類
/**
* Called when the activity is first created. Set the web view layout and
* get the title and file to be displayed.
*
* @param savedInstanceState
* Is used to save the state of the created Activity.
*
* @author Yuriy Stanchev
*
* @email [email protected]
*
* @date 11 Mar 2012
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String title = (String) extras.get("title");
String file = (String) extras.get("file");
setContentView(R.layout.about);
setTitle(title);
WebView view = (WebView) findViewById(R.id.web);
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();
view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
view.loadUrl(file);
}