2013-02-25 95 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

相關問題