How to change spinner text size and text color?

后端 未结 24 1976
囚心锁ツ
囚心锁ツ 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:23

    For someone who needs only Style way for AppCompat.

    Result

    styles.xml

    
        ... 
        
    
    

    your_spinner_layout.xml

    
    
        ...
    
        
    
        
    
        ...
        
    

    Plus
    And if you want to set android:entries programmatically with defined style.
    Try this.

    AppCompatSpinner spinner = findViewById(R.id.content_spinner);
    CharSequence[] entries = getResources().getTextArray(R.array.shipping_tracking_carrier_names);
    ArrayAdapter adapter = new ArrayAdapter<>(spinner.getContext(), android.R.layout.simple_spinner_item, entries);
    adapter.setDropDownViewResource(android.support.v7.appcompat.R.layout.support_simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    

    As in the code, using same Context with the Spinner is most important thing.

    spinner.getContext()
    

提交回复
热议问题