开发者

Android: open URL in a new window WITHOUT leaving app

开发者 https://www.devze.com 2023-03-05 23:12 出处:网络
Is there anyway I can open web when user clicks on TextView, in a new window without leaving the app, it\'s like in iPhone when you click on an URL it shows you a new browser window, but there is a BA

Is there anyway I can open web when user clicks on TextView, in a new window without leaving the app, it's like in iPhone when you click on an URL it shows you a new browser window, but there is a BACK button you can click to go back to previo开发者_C百科us screen?

Thanks!


You can create your own Browser Activity with a WebView in the layout. Inherently it is not going to have any of the functionality of the actual stock browser app though, other than displaying the web page. You'll have to add in the forward / back buttons if you want them and anything else you need. If you don't need any of that stuff then you should be fine with just a plain WebView. When you press the back button on the device it should close that activity and take you back to the one you started in.

Edit:

To get callbacks from a WebView when the user clicks a link you can use the WebViewClient shouldOverrideUrlLoading() method, like this:

wv.setWebViewClient(new WebViewClient() {
            /* On Android 1.1 shouldOverrideUrlLoading() will be called every time the user clicks a link,
             * but on Android 1.5 it will be called for every page load, even if it was caused by calling loadUrl()! */
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                Log.i(myTag, url);


                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)) ;
                startActivity(i);
                return true;


            }
        });

For a TextView its a little bit more work, You'll have to make your own copy of the Linkyfy class and use a TransformFilter to make the links behave however you want them to. Check out this question for an example Android Linkify both web and @mentions all in the same TextView


Maybe a WebView is what you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号