开发者

How to create custom ProgressBar and use it in Widget?

开发者 https://www.devze.com 2023-03-17 06:52 出处:网络
I would like use my own extended ProgressBar class in Widget. I has created really simple MyProgressBar and if I place this into standart activity layout, it works. Of course I set also Style attribiu

I would like use my own extended ProgressBar class in Widget. I has created really simple MyProgressBar and if I place this into standart activity layout, it works. Of course I set also Style attribiute to "?android:attr/progressBarStyleHorizontal" in MyProgressBar property in designer.

But if I do same and place it to Widget layout, its visible good in layout designer in eclipse, however, widget does not work in traget. There is only "Problem loaing widget" message showed instead of widget layout .... on target device....

Source code for MyProgressBar is here :

public class MyProgressBar extends ProgressBar {

public MyProgressBar(Context context) {   
    super(context);   
}   

public MyProgressBar(Context context, AttributeSet attrs) {   
    super(context, attrs);   
}   

public MyProgressBar(Context context, AttributeSet attrs, int defStyle) {   
    super(context, attrs, defStyle);   
}   

@Override  
protected synchronized void onDraw(Canvas canvas) {   
    // First draw the regular progress bar, then cus开发者_开发技巧tom draw our text   
    super.onDraw(canvas);
}   

}


Widget don't support custom view. If you just change the progressbar's background,you can use the system's progressbar,and change the drawable in the layout xml.


App Widget can support the following layout classes: FrameLayout, LinearLayout, RelativeLayout, GridLayout.

And the following widget classes: AnalogClock, Button, Chronometer, ImageButton, ImageView, ProgressBar, TextView, ViewFlipper, ListView, GridView, StackView, AdapterViewFlipper.

Descendants of these classes are not supported.

Copied from: http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

0

精彩评论

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