开发者

Need help changing from stock android browser to webview

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 tried so many things and I keep getting errors and eclipse keep开发者_高级运维s launching the debug perspective and I'm stuck..

// XXXX.edu Button
        Button XXXX_Button = (Button)findViewById( R.id.XXXX_Button );
        XXXXXX_Button.setOnClickListener( new View.OnClickListener()
        {
        public void onClick(View v)
        {
            Uri uri = Uri.parse( "http://www.XXXXXX.edu/" );
            startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
        }
        });


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,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

    <WebView
        android:id="@+id/wv"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</LinearLayout>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜