java - 我的网络视图不工作。找不到符号?
问题描述
我的错误是找不到符号类 WebViewClient,也找不到符号类 WebChromeClient huhu 我在教程中尝试了所有内容..
这是我的 MainActivity.java:
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
WebView superWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
superWebView = (WebView) this.findViewById(R.id.myWebView);
superWebView.loadUrl("https://www.google.com");
superWebView.getSettings().setJavaScriptEnabled(true);
superWebView.setWebViewClient(new WebViewClient());
superWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onReceivedIcon(Webview view, Bitmap icon) {
super.onReceivedIcon(view,icon);
}
});
}
}
这是我的 activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<WebView
android:id="@+id/myWebView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
这是我的 AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
这是我第一次尝试在android studio中尝试webview ..安装了sdks等..我不知道我是否错过了一些东西..
我应该以相对布局查看网站或谷歌,但 JAVA 似乎找不到 sysmbol .. 需要帮助,非常感谢!
解决方案
为了使用onReceiveIcon()
,你应该使用setWebChromeClient。
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
progressBar.setProgress(newProgress);
}
@Override
public void onReceivedIcon(WebView view, Bitmap icon) {
super.onReceivedIcon(view, icon);
webImage.setImageBitmap(icon);
}
});
推荐阅读
- javascript - 如何在行模板中进行索引搜索?JavaScript
- javascript - 如何在 react-input-range 中添加自定义箭头
- swiftui - 可调整大小的 UITextView 的 sizeThatFits 在 UIViewRepresentable 中给出了错误的大小
- android - Android:有没有办法在 textView 中使用 autoSize 而不会破坏单个单词?
- javascript - 如何在Angular 9+中使用outerHtml?
- python - 我不再有对齐问题,但是,当我打印出我的 X 和 O 时,它们旁边会有一个 0。有谁知道不同的解决方案?
- javascript - Highcharts 动态更新 x 轴类别
- c# - 设置播放器 go.transform.position 不改变位置
- excel - 使用 Visual Basic 将 PDF 插入 Excel
- javascript - 我可以覆盖导入到父级的祖父级方法吗?