How can I add WebView into a Widget?

有些话、适合烂在心里 提交于 2019-12-10 01:10:00

问题


I'm trying to make a recording Widget where the user interface would be loaded from HTML page in WebView. Is this possible? I've been trying to load url into Widget but I get all sorts of errors and my program crashes. I'm new to Android development and don't really know how this stuff works yet.

This is my Widget provider class:

public class RecordAppWidgetProvider extends AppWidgetProvider {
WebView webview;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("http://www.google.com");
    webview.setWebViewClient(new WebViewClient());

}
}

I think I'll have to load the WebView in some way, normally I do it with this:

webview = (WebView) findViewById(R.id.webview);

But it doesn't work here, I think findViewById is from Activity?


回答1:


You can't use WebView within widget layout, sorry. As the documentation states the only supported views are:

  • AnalogClock
  • Button
  • Chronometer
  • ImageButton
  • ImageView
  • ProgressBar
  • TextView

Honeycomb Added more supported views:

  • ViewFlipper
  • ListView
  • GridView
  • StackView
  • AdapterViewFlipper



回答2:


I believe it is not possible to use webviews in a widget. Only more static things like lists and pictures can be used.



来源:https://stackoverflow.com/questions/5402598/how-can-i-add-webview-into-a-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!