添加自定义textView并在微调器中更改文本重力

时间:2014-10-28 17:03:36

标签: android textview android-spinner

我有一个自定义微调器,我想自定义更多。具体来说,我想让旋转器中的文本显示一个笔划,并确保它位于微调器的中心。

我的自定义微调器代码现在看起来像这样:

public class MyCustomSpinnerAdapter extends ArrayAdapter<String> {

    private Typeface roboto;
    private Context ctx;
    private int fontSize = 22;


    public MyCustomSpinnerAdapter(Context ctx, int TextViewResId, String[] objects) {
        super(ctx, TextViewResId, objects);
        this.ctx = ctx;
        String locale = Locale.getDefault().toString();

        if (locale.equals("iw_IL") || locale.equals("he_IL")) {
            roboto = Typeface.createFromAsset(ctx.getAssets(), "fonts/yehudaclmboldwebfont.ttf");
        } else {
            roboto = Typeface.createFromAsset(ctx.getAssets(), "fonts/pacifico.ttf");
        }

    }

    public MyCustomSpinnerAdapter(Context ctx, int TextViewResId, String[] objects, int fontSize) {
        super(ctx, TextViewResId, objects);
        this.ctx = ctx;
        String locale = Locale.getDefault().toString();

        if (locale.equals("iw_IL") || locale.equals("he_IL")) {
            roboto = Typeface.createFromAsset(ctx.getAssets(), "fonts/yehudaclmboldwebfont.ttf");
        } else {
            roboto = Typeface.createFromAsset(ctx.getAssets(), "fonts/pacifico.ttf");
        }
        this.fontSize = fontSize;

    }


    public View getView(int position, View convertView, ViewGroup parent) {


        View v = super.getView(position, convertView, parent);

        ((TextView) v).setTypeface(roboto);
        ((TextView) v).setTextColor(ctx.getResources().getColor(R.color.jenyBlue));
        ((TextView) v).setTextSize(fontSize);
        return v;
    }


    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        View v = super.getDropDownView(position, convertView, parent);
        ((TextView) v).setTypeface(roboto);


        return v;
    }

}

0 个答案:

没有答案