自定义TextView可见时,Android Spinner performClick不会展开Spinner

时间:2018-06-27 03:43:54

标签: android android-spinner

我的布局中有一个自定义的textview

public class CircularTextView extends AppCompatTextView {

    private float strokeWidth;
    private int strokeColor;
    private int solidColor;

    public CircularTextView(Context context) {
        super(context);
    }

    public CircularTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CircularTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    public void draw(Canvas canvas) {

        Paint circlePaint = new Paint();
        circlePaint.setColor(solidColor);
        circlePaint.setFlags(Paint.ANTI_ALIAS_FLAG);

        Paint strokePaint = new Paint();
        strokePaint.setColor(strokeColor);
        strokePaint.setFlags(Paint.ANTI_ALIAS_FLAG);

        int  h = this.getHeight();
        int  w = this.getWidth();

        int diameter = ((h > w) ? h : w);
        int radius = diameter/2;

        this.setHeight(diameter);
        this.setWidth(diameter);

        canvas.drawCircle(diameter / 2.0f , diameter / 2.0f, radius, strokePaint);

        canvas.drawCircle(diameter / 2.0f, diameter / 2.0f, radius-strokeWidth, circlePaint);

        super.draw(canvas);
    }

    public void setStrokeWidth(int dp)
    {
        float scale = getContext().getResources().getDisplayMetrics().density;
        strokeWidth = dp*scale;

    }

    public void setStrokeColor(String color)
    {
        strokeColor = Color.parseColor(color);
    }

    public void setSolidColor(String color)
    {
        solidColor = Color.parseColor(color);

    }

}

还有一个微调框(如果需要,可以提供布局的详细信息)。我将微调适配器设置如下:

        spinnerFavBrand = view.findViewById(R.id.spinnerFavBrand);
        final ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, brandNameList);
        dataAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
        spinnerFavBrand.setAdapter(dataAdapter);

我通过使用Button的onClick()中的performClick()来扩展微调器。

ibEditFavBrand.setOnClickListener(v -> spinnerFavBrand.performClick());

当隐藏了CircularTextView时,微调器可以正常打开,但是当我将CircularTextView的可见性设置为可见时,我仍然可以在按钮的onClick()方法中接收到click事件,但是performClick()似乎没有效果现在。

0 个答案:

没有答案