我想在Widget中使用我自己的扩展ProgressBar类。我创建了非常简单的MyProgressBar,如果我把它放到标准活动布局中,它就可以了。当然我还在设计师的MyProgressBar属性中将Style attribiute设置为“?android:attr / progressBarStyleHorizontal”。
但是,如果我这样做并将其放置到Widget布局,它在eclipse中的布局设计器中可见,但是,widget在traget中不起作用。在目标设备上只显示“问题借用小部件”消息而不是小部件布局....
MyProgressBar的源代码在这里:
公共类MyProgressBar扩展了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 custom draw our text
super.onDraw(canvas);
}
}
答案 0 :(得分:0)
小部件不支持自定义视图。 如果您只是更改进度条的背景,则可以使用系统的进度条,并更改布局xml中的drawable。
答案 1 :(得分:0)
App Widget可以支持以下布局类:FrameLayout,LinearLayout,RelativeLayout,GridLayout。
以下小部件类:AnalogClock,Button,Chronometer,ImageButton,ImageView,ProgressBar,TextView,ViewFlipper,ListView,GridView,StackView,AdapterViewFlipper。
不支持这些类的后代。
复制自:http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout