2013-02-25 92 views
0

我想将WebView放入烤面包或Webview中显示在屏幕的一小部分上。Android 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,代码从Android网站敬酒部分obrained了Java的部分:

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

谢谢提前:)

+0

我使用web视图网页视图=(web视图)findViewById(R.id.webviewEquationsView); webview.loadUrl(“file:///android_asset/dsfsdf.....html”);在其他类中导入webview – Gabi 2013-02-25 23:22:12

+0

问题:你在哪里设置了webview的url。 – Pragnani 2013-02-26 04:21:25

+0

另外我不知道为什么一个巨魔把我投下来,因为我花了很多年试图找到有用的东西,我还提供了一些代码 – Gabi 2013-03-03 19:28:55

回答

0

试试这个

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

从inflatter视图获取web视图

首先添加URL到web视图

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

谢谢,但我已经尝试过,并且它没有工作 – Gabi 2013-03-03 19:21:49

+0

由于某种原因,如果我使用你的代码应用程序崩溃。 – Gabi 2013-03-03 19:22:52

+0

我找到了一个不同的解决方案 – Gabi 2013-03-03 19:56:52

相关问题