【问题标题】:Need help changing from stock android browser to webview需要帮助从库存 android 浏览器更改为 webview
【发布时间】:2011-07-25 21:04:21
【问题描述】:

好的,我已经完成了我的应用程序,我正在对其进行一些小的调整,一件事是我希望我的网络链接在 webview 而不是股票浏览器中启动......我已经尝试了很多东西,我不断收到错误,eclipse 不断启动调试透视图,我被卡住了..

// 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 ) );
        }
        });

【问题讨论】:

    标签: android browser webview android-webview


    【解决方案1】:

    您需要扩展WebViewClient,并在其中启动网址。

    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.
    

    在你的布局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>
    

    【讨论】:

    • 我不明白如何在我的 java 文件中使用该部分,我在我的 xml 中得到了该部分,但是 java 文件把我弄乱了,我需要为我的每个文件创建一个字符串吗?链接,然后放入@string/website1,字符串网站1 是我到网站的链接。就像我说的那样,这对我来说是全新的,我刚刚开始开发 Android 应用程序,所以我非常感谢所有的帮助..
    • 在上面的代码中,只需将baseUrl 替换为您的硬编码路径即可。一旦你得到它的工作,你可以看看String Resources
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    相关资源
    最近更新 更多