开发者

Android - Using custom View in Widget

开发者 https://www.devze.com 2023-01-10 01:50 出处:网络
i made a 开发者_JAVA百科extended a View, overwrote the 3 View Contructors and tried to insert it on my xml of a widget.

i made a 开发者_JAVA百科extended a View, overwrote the 3 View Contructors and tried to insert it on my xml of a widget.

The Exception is:

java.lang.ClassNotFoundException: com.mypackage.myView in loader dalvik.system.PathClassLoader@4001e710

is it possible to use custom views in Widgets?


is it possible to use custom views in Widgets?

If by "Widgets" you mean "app widgets", then, no. You cannot use custom View classes in app widgets.


But you could use an ImageView which is supported in a widget:

  1. Create a Bitmap and draw with a Canvas on it:
Bitmap mBitmap = Bitmap.createBitmap(mWidht, mHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mBitmap);
canvas.drawText("test", 0, 30, new Paint());
  1. Assign this bitmap to ImageView in the widget by using
remoteViews.setImageBitmap(viewID, mBitmap);

See this post for more information

0

精彩评论

暂无评论...
验证码 换一张
取 消