我目前正在我的应用程序中实现某些功能,因为事实证明默认Web视图不支持此类功能。 那么,我是否有可能在我的应用程序中内置 chrome web view 而不是 android默认Web视图或将其重定向到 chrome < / strong>浏览器。 我目前正在使用棉花糖。我开始了解 NOUGAT 版本中实现的此功能。但是,我需要 API&lt; 23 。
以下是我的代码:
webView = (WebView) findViewById(R.id.fullscreen_content);
// webView.setWebViewClient();
//you can also link to a website. Example:
//webView.loadUrl("www.google.com");
//I have included web permissions in the AndroidManifest.xml
//
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
//loads the WebView completely zoomed out
webView.getSettings().setLoadWithOverviewMode(true);
//true makes the Webview have a normal viewport such as a normal desktop browser
//when false the webview will have a viewport constrained to it's own dimensions
webView.getSettings().setUseWideViewPort(true);
//override the web client to open all links in the same webview
webView.setWebViewClient(new MyWebViewClient());
webView.setWebChromeClient(new MyWebChromeClient());
webView.loadUrl(URL);
答案 0 :(得分:0)
尝试使用Building Web Apps in WebView从<{3}}派生的示例代码:
public class MainActivity extends AppCompatActivity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView)findViewById(R.id.webview);
webView.setWebChromeClient(new WebChromeClient());
String urlString="https://www.youtube.com/watch?v=miomuSGoPzIe";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
intent.setPackage("com.android.chrome");
try {
startActivity(intent);
} catch (ActivityNotFoundException ex) {
Log.v("MainActivity", "NO CHROME APP INSTALLED");
intent.setPackage(null);
startActivity(intent);
}
}
}
这里是activity_main.xml中的WebView
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
我在Nexus手机中安装了Firefox和Chrome,它在Chrome中打开了WebView,所以我觉得它很有用。