0

私はしばらく複合コンポーネントを使用して成功しています。私は少し問題に直面しており、簡単な解決策があるかどうか疑問に思っています:

カスタム シークバーが必要です。すでにスタイル/テーマとして持っています。かなり精巧なものなので、コードで複製したくありません。すべてのシークバーは、より複雑なブロックの一部としてプログラムによって作成され、これを変更するオプションはありません。

シークバーとこのスタイルを適用して XML を作成し、この xml をシークバーを拡張するだけの複合クラスに「膨張」させる方法はありますか?

インフレート機能はビューグループのみを受け入れますが、それらの「replaceroot」バージョンは通常のビューでもうまく機能する可能性があり、まさに私が必要としているものです。

前もって感謝します

public class SeekBarYellow extends SeekBar {

    public SeekBarYellow(Context context) {
        super(context);
        construct_programmatically(context);
    }
    private void construct_inflating(Context context) {
        // how do I inflate a <SeekBar android:style=xxxx android ...>
        // into here? (R.layout.seekbar_yellow)
    }

    // i'd like to avoid this, by inflating R.layout.seekbar_yellow
    private void construct_programmatically(Context context) {
        Resources r=context.getResources();
        this.setThumb(r.getDrawable(R.drawable.scrubber_control_selector_holo_dark));
        this.setProgressDrawable(r.getDrawable(R.drawable.scrubber_progress_horizontal_holo_dark));
        this.setIndeterminateDrawable(r.getDrawable(R.drawable.scrubber_progress_horizontal_holo_dark));
        this.setMinimumHeight(13);
        this.setMinimumWidth(13);
        this.setThumbOffset(16);
        this.setPadding(16,0,16,0);
    }
}
4

1 に答える 1