3

カスタム NumberPicker 用に複合ドローアブルを作成しようとしています。メインビューは実際にはEditTextであることがわかり、EditTextには複合ドローアブル(DrawableLeft、DrawableRightなど)があるため、設定しようとしましたが、NumberPickerが実際に表示されると、そこにはありません。それを機能させるために他にできることはありますか?

私の現在のコード -

public class ViewPicker extends NumberPicker {
    private int textSize = -1;

    public ViewPicker(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    public ViewPicker(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public ViewPicker(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void addView(View child) {
        super.addView(child);
        updateView(child);
    }

    @Override
    public void addView(View child, int index,
            android.view.ViewGroup.LayoutParams params) {
        super.addView(child, index, params);
        updateView(child);
    }

    @Override
    public void addView(View child, android.view.ViewGroup.LayoutParams params) {
        super.addView(child, params);
        updateView(child);
    }

    private void updateView(View view) {
        if (view instanceof EditText) {
            EditText editText = (EditText) view;
            if (textSize > 0)
                editText.setTextSize(textSize);
            editText.setTextColor(Color.parseColor("#333333"));

            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

            BitmapDrawable draw = new BitmapDrawable(getResources(),bitmap);

            editText.setCompoundDrawables(draw, null, null, null);
        }
    }

    public int getTextSize() {
        return textSize;
    }

    public void setTextSize(int textSize) {
        this.textSize = textSize;
    }
}

これに利用できる代替方法があれば教えてください。

4

0 に答える 0