0

我正在尝试将 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>

这是我想放置webview的java部分,代码来自android website-toast部分:

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();

先感谢您 :)

4

1 回答 1

0

尝试这个

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

从 inflatter 视图中获取 WebView

首先将 url 添加到 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();
于 2013-02-26T04:23:52.690 回答