Widget で独自の拡張 ProgressBar クラスを使用したいと思います。非常にシンプルな MyProgressBar を作成しました。これを標準のアクティビティ レイアウトに配置すると、機能します。もちろん、デザイナの MyProgressBar プロパティで Style 属性も "?android:attr/progressBarStyleHorizontal" に設定します。
しかし、同じことをしてウィジェット レイアウトに配置すると、Eclipse のレイアウト デザイナーに表示されますが、ウィジェットはトラゲットでは機能しません。ウィジェットのレイアウトの代わりに「ウィジェットの読み込みに問題があります」というメッセージのみが表示されます....ターゲットデバイスで....
MyProgressBar のソース コードは次のとおりです。
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 custom draw our text
super.onDraw(canvas);
}
}