How do I make a Spinner's “disabled” state look disabled?

后端 未结 13 1517
傲寒
傲寒 2020-12-09 03:00

When I disable my Spinner it looks almost exactly like it did prior to being disabled, i.e.

Before

13条回答
  •  感情败类
    2020-12-09 03:07

    The .getSelectedView() did not work for me. So I tricked the Spinner to show being disabled.

    You will need to define your own colors for the disabled look.

    For Example:

    R.color.blue_text //means enabled
    R.color.gray_text //means disabled
    

    So to disable my spinner:

    ((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.gray_text));
    mySpinner.setEnabled(false);
    mySpinner.setFocusable(false);
    

    To enable my spinner:

    ((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.blue_text));
    mySpinner.setEnabled(true);
    mySpinner.setFocusable(true);
    

    You don't need to change styles or modify any XML. Just do this in your code, even within event methods, you should be fine.

提交回复
热议问题