我有一個CustomWebViewClass:似乎無法通過PARAMS同構造函數
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class CustomWebView extends Activity{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String url = intent.getStringExtra("url");
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
//progress bar optional
getWindow().requestFeature(Window.FEATURE_PROGRESS);
final Activity activity = this;
Toast.makeText(activity, "YO! " + url, Toast.LENGTH_SHORT).show();
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 1000);
}
});
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
webview.loadUrl(url);
}
}
從另一個類(本質上是一個按鈕)我想調用這個類的意圖傳遞給它的URL像這樣:
Intent webView = new Intent(getContext(), CustomWebView.class);
webView.putExtra("url", "http://google.com");
webView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(webView);
但我得到一個黑屏或一個錯誤。顯然,我做錯了什麼,請幫助
哦,我的表現有這樣的:
<activity android:name=".CustomWebView"
android:label="CustomWebView"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="com.sapientnitro.lcinstore2.CUSTOMWEBVIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
感謝我試着但有些東西仍然是錯誤的,因爲我得到這個錯誤:03-27 10:50:30.240:E/Android運行時(6073):java.lang.RuntimeException:無法實例化活動ComponentInfo {com.sapientnitro.lcinstore2/com.sapientnitro.lcinstore2.CustomWebView}:java.lang.InstantiationException:com.sapientnitro.lcinstore2.CustomWebView – erik 2012-03-27 15:50:25
似乎是最終的問題是:getWindow()。requestFeature(Window.FEATURE_PROGRESS);在內容之前被調用?我剛剛評論它,現在它的作品.. – erik 2012-03-27 16:22:14