【问题标题】:Load and external Url and Maintain the WebView hidden加载和外部 URL 并保持 WebView 隐藏
【发布时间】:2013-04-08 00:49:59
【问题描述】:

有一个带有 Vertical LinearLayout 的 Android Activity。第一个屏幕组件是一个简单的 TextView,在 WebView 的正下方,可见性消失了。

网页有与服务器通信的javascript代码,没有可视化组件。所以我需要在可见性消失的情况下保持它,即隐藏,在活动屏幕中不占用空间。

然后问题是当我执行 webView.loadUrl 时。它打开设备浏览器。在模拟器中,它切换到另一个活动,webview 占据了所有屏幕。

我怎样才能让它工作?如何加载和维护 webView 完全隐藏

提前致谢

我的布局是这样的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#ffe3d0">
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Demo: WebView"
            android:layout_gravity="center" style="@style/MainLabel" android:autoText="false" android:id="@id/mainLabel"
            android:textColor="#3c3f41"/>
    <WebView
            android:layout_width="fill_parent"
            android:layout_height="30dp"
            android:id="@id/webView" android:visibility="gone"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/secondTextView"
            android:id="@+id/textView" android:textColor="#1635ff" android:layout_gravity="center"/>
</LinearLayout>

我的活动代码是这样的:

@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    WebView webview = (WebView) findViewById(R.id.webView);

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webview.loadUrl("http://google.com/");
}

【问题讨论】:

    标签: android webview


    【解决方案1】:

    编辑:通过 AsyncTask 函数尝试调用您的 url 并通过进度条隐藏所有屏幕...

    【讨论】:

    • 抱歉,我是 Android 开发新手。我怎样才能做到这一点 ?你有任何代码。我在原始问题文本中添加了我的文件的副本
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    相关资源
    最近更新 更多