【发布时间】:2014-01-17 09:01:09
【问题描述】:
在我的 android 应用程序中,我有 textview 来证明我使用了 webview 的文本。我在xml 中设置背景image。但问题是,当我在应用程序的主菜单中按 button 以打开新活动以显示文本时。它的第一个显示背景和一段时间后显示文本。我想当我按下button 时立即显示文本。
代码-
setContentView(R.layout.benefits);
WebView view = new WebView(this);
view.setVerticalScrollBarEnabled(true);
((LinearLayout)findViewById(R.id.bText)).addView(view);
view.setBackgroundColor(0x00000000);
view.loadData(getString(R.string.benef), "text/html", "utf-8");
Xml-
<?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:gravity="center_horizontal"
android:background="@drawable/back">
<View
android:id="@+id/top_space_waster"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="@null"
android:gravity="center"
android:layout_weight="3" />
<LinearLayout
android:id="@+id/bText"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:gravity="center">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:gravity="center_horizontal">
<Button
android:text="BACK"
android:id="@+id/back2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="32sp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:background="@null" />
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
有人建议我使用 Asynctask,但我不认为它有助于立即显示文本。
-
显示文字需要多少时间?
-
您首先加载您的 WebView 并使其不可见,然后单击按钮使其可见。
-
确定如何以编程方式进行?
-
最初让你的 webview 像这样
WebView view = new WebView(this); view.setVisibility(View.INVISIBLE);不可见,然后点击按钮view.setVisibility(View.VISIBLE);。
标签: android xml webview background