[英]How can i add here a webview?
我在這里應該如何處理我的腳本,我已經嘗試了所有方法,但無濟於事。.他的webview錯誤提示?
package com.dehvb.dehvbapp;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class ProgrammaFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_programma, container, false);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.example.com");
return rootView;
}
}
public class ProgrammaFragment extends Fragment {
Webview wv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_programma, container, false);
wv = (WebView) rootView.findViewById(R.id.yourWebviewId);
//Use the thread policy only if your load URL doesn't work on main thread.
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
wv.loadUrl("http://www.example.com");
return rootView;
}
}
ps起飛import com.dehvb.deheerenveenseboys.R;
從導入中,可能會導致一些問題。
如果您已經在布局文件中擁有了Webview而不是直接使用它!
WebView wb = (WebView)rootView.findViewById(R.id.webView);
wb.loadUrl(url);
將網址替換為您的網址,例如“ https://stackoverflow.com/ ”。 希望這對您有所幫助!
編輯:首先完全按照以下方式更新清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dehvb.dehvbapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.dehvb.dehvbapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
和你的ProgrammaFragment.class
public class ProgrammaFragment extends Fragment
{
WebView wv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_programma, container, false);
wv = (WebView) rootView.findViewById(R.id.WebView1);
//Use the thread policy only if your load URL doesn't work on main thread.
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
wv.loadUrl("https://stackoverflow.com/");
return rootView;
}
}
我已經測試過了,如果您願意,我可以發布屏幕截圖!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.