Android WebView敬酒

时间:2013-02-25 23:20:36

标签: android webview toast

我正在尝试将WebView放入toast或Webview中,以便在屏幕的一小部分显示。

这是xml:

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

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/padding_medium"
        android:text="@string/hello_world"
        tools:context=".Webview" />
    <WebView 
        android:id="@+id/webviewEquationsView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</RelativeLayout>
</LinearLayout>

这里是java的一部分,我想放置webview,代码从android网站吐司部分:

LayoutInflater inflater = getLayoutInflater();     
View layout = inflater.inflate(R.layout.toast_equation_menu,(ViewGroup)     findViewById(R.id.toast_layout_root));
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();

提前谢谢你:)

1 个答案:

答案 0 :(得分:0)

试试这个

  LayoutInflater inflater = getLayoutInflater();     
    View layout = inflater.inflate(R.layout.toast_equation_menu,(ViewGroup)findViewById(R.id.toast_layout_root));

从inflatter视图中获取WebView

首先将网址添加到WebView

   WebView webview = (WebView) layout.findViewById(R.id.webviewEquationsView);   webview.loadUrl("http://www.google.com");

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();