How to change spinner text size and text color?

后端 未结 24 1989
囚心锁ツ
囚心锁ツ 2020-11-22 11:35

In my Android application, I am using spinner, and I have loaded data from the SQLite database into the spinner, and it\'s working properly. Here is the code for that.

24条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 12:34

    Here is a link that can help you to change the color of the Spinner:

    Click here

    
    

    You need to create your own layout file with a custom definition for the spinner item spinner_item.xml:

    
    

    If you want to customize the dropdown list items, you will need to create a new layout file. spinner_dropdown_item.xml:

    
    
    

    And finally another change in the declaration of the spinner:

    ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
    R.array.planets_array, R.layout.spinner_item);
    
    adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
    spinner.setAdapter(adapter);
    

    That's it.

提交回复
热议问题