我有一个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