【问题标题】:Multiple URLs in one WebView一个 WebView 中的多个 URL
【发布时间】:2018-10-25 18:29:52
【问题描述】:

我想制作两个按钮和一个 WebView,但不知何故我的应用程序停止了。我找不到错误。有人可以帮我吗?

主Java:

public void setButtononClick(View v) {
    String url = null;

    switch(v.getId()) {
        case R.id.button1:
            url="https://www.delfi.lt";
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://delfi.lt")));
            break;
        case R.id.button2:
            url= "https://www.youtube.com";
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com")));
            break;
    }

    Intent launchBrowser = new Intent(Intent.ACTION_VIEW );
    Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url)); startActivity(intent);
    }}

WebView ACC JAVA

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);

    // Get reference of WebView from layout/webviewex.xml
    webView = (WebView) findViewById(R.id.webView1);


    // Get URL from Intent
    String URL = getIntent().getExtras().getString("URL");

    // Load website
    webView.loadUrl(URL);
}

也许有人可以帮助我?我想我什么都试过了。

【问题讨论】:

  • 能否分享原帖中的错误或stacktrace?
  • 没有错误。只有“您的应用已停止”

标签: java android url button android-activity


【解决方案1】:
public void onClick(View v) {
String url;

        switch(v.getId()) {
            case R.id.button1:
               url="https://www.delfi.lt";
               launchBrowserWithUri(Uri.parse(url))
                break;
            case R.id.button2:
               url= "https://www.youtube.com";
                   launchBrowserWithUri(Uri.parse(url))
                break;
        }



Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uri);
    if (getActivity() != null && launchBrowser.resolveActivity(getActivity().getPackageManager()) != null){
        startActivity(launchBrowser);
    }  

【讨论】:

  • 我编辑了我的代码,你能看一下吗?因为现在应用程序不会崩溃,但它是空白页面......没有按钮,什么都没有。
猜你喜欢
  • 1970-01-01
  • 2014-10-06
  • 2018-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多