【问题标题】:I can't set a Specific Url in Webview in fragment in android [closed]我无法在 android 的片段中的 Webview 中设置特定的 URL [关闭]
【发布时间】:2014-10-19 21:53:31
【问题描述】:

我在 android 的 Webview 中遇到 Setdata 问题 问题是我无法在 Webview 中设置特定的 Url 例如我可以设置http://www.youtube.com 但我不能设置 http://www.youtube.com/user/androiddevelopers我不知道该怎么办,为什么 它不工作

public class FragmentA extends Fragment {
public FragmentA() {
    Log.i("in :","on cons");
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {



    View mainView = inflater.inflate(R.layout.first_fragment, container, false);

    WebView wv = (WebView)mainView.findViewById(R.id.url);

    wv.setWebViewClient(new MyWebViewClient());

    wv.getSettings().setPluginState(WebSettings.PluginState.ON);

    wv.getSettings().setBuiltInZoomControls(false);

    wv.getSettings().setSupportZoom(false);

    wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

    wv.getSettings().setAllowFileAccess(true);

    wv.getSettings().setDomStorageEnabled(true);


    wv.loadUrl("here is my problem");

    return mainView;


}

public class MyWebViewClient extends WebViewClient
{
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        if(url.contains("here is where i will put the url to check") == true) {
            view.loadUrl(url);
        }
        else
        {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);

        }
        return true;

    }
   }
  }

【问题讨论】:

  • 您没有“上传 URL”。没办法。
  • @MarcinOrlowski 谢谢你的回答.. 我的意思是我不能 setData(Uri.parse(Url));用我写的

标签: android url web view webview


【解决方案1】:

这可能会解决您的问题。

webView.setWebViewClient(new WebViewClient(){ public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url != null && url.startsWith("http://")) { view.getContext().startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } else { return false; } } });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多