如何在附加到视图的布局中访问Web视图以加载页面。
我尝试了一些可能可行的方法,包括
void loadWeb() {
uiH.post(new Runnable() {
@Override
public void run() {
LoadingWeb = (WebView) findViewById(R.id.web);
LoadingWeb.setWebChromeClient(new WebChromeClient());
LoadingWeb.getSettings().setJavaScriptEnabled(true);
LoadingWeb.loadUrl("file:///android_asset/www/page.html");
}
}); }
但是不起作用
java.lang.NullPointerException:尝试调用虚拟方法 空对象上的'boolean android.os.Handler.post(java.lang.Runnable)' 参考
如何将页面加载到波纹管附件视图中
final IntentFilter theFilter = new IntentFilter();
theFilter.addAction(myDrawerReceiver);
this.myDrawingReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final Bundle bundle = intent.getExtras();
try{
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.FILL;
WindowManager wm = (WindowManager) app.appContext.getSystemService(
Context.WINDOW_SERVICE
);
if(bundle.get("draw").equals("draw")){
loadWeb();
wm.addView(myWeb, params);
}
else if(bundle.get("draw").equals("undraw")){
wm.removeView(myWeb);
}
}catch (Exception e){
Log.d(ussd.TAG,e.toString());
}
}
};
this.registerReceiver(this.myDrawingReceiver, theFilter);
webview web 位于布局myWeb
谢谢