Need help changing from stock android browser to webview

前端 未结 1 1669
闹比i
闹比i 2021-01-22 23:00

Ok, so I\'ve got my app done, and I\'m working on minor tweaks for it, and one thing is I would prefer my web links to launch in webview instead of the stock browser... I\'ve tr

1条回答
  •  隐瞒了意图╮
    2021-01-22 23:28

    You need to extend WebViewClient, and launch the url within that.

    public class WebActivity extends Activity
    {
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            webview = (WebView) findViewById(R.id.wv);
            webview.setWebViewClient(new WebC());
            webview.loadUrl(baseUrl);
        }
    
        public class WebC extends WebViewClient
        {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                super.onReceivedError(view, errorCode, description, failingUrl);
            }
    
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
        ... etc.
    

    And in your layout xml,

    
    
        
    
    

    0 讨论(0)
提交回复
热议问题