【问题标题】:builder (android.content.context) in builder cannot be applied to Activitybuilder中的builder(android.content.context)不能应用于Activity
【发布时间】:2015-10-28 13:20:42
【问题描述】:

我正在尝试在 webview 中加载网页。在 Dialog 中加载 webview。我尝试过此代码。但在红线中显示错误 builder (android.content.context) in builder cannot be applied to .. 并在 this 下划线。

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    webview=(WebView)findViewById(R.id.webview);
    webview.setWebViewClient(new WebViewClient();
    webview.loadUrl("http://example.com/abc.html");
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setView(webview);
    dialog.setPositiveButton("Okay", null);
    dialog.show();
}

【问题讨论】:

  • 尝试使用获取上下文

标签: android


【解决方案1】:

试试这个->

WebView webView = new WebView(this);
webView.loadUrl("http://www.google.com/");
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setView(webView);
dialog.setPositiveButton("Okay", null);
dialog.show();

也检查一下--> android: webview inside dialog or popup

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    相关资源
    最近更新 更多