Search code examples
androidfontsspinnerdropdowntypeface

How I can set typeface (font) of this spinner text?


I don't understand why I don't set the font for this spinner-text in a form activity.

IMAGE

private void addListenerOnSpinnerItemSelection() {
    spinner.setOnItemSelectedListener(new CustomOnItemSelectedListener());
    colorescelto = spinner.getSelectedItem().toString();
}



private void addItemsOnSpinner() {
    spinner = (Spinner) findViewById(R.id.colorchoose);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.colori, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
}



// get the selected dropdown list value
public void addListenerOnButton() {
    spinner = (Spinner) findViewById(R.id.colorchoose);
}





<Spinner
                    android:id="@+id/colorchoose"
                    android:layout_width="250dp"
                    android:layout_height="40dp"
                    android:layout_centerInParent="true"
                    android:layout_below="@id/datanascita"
                    android:layout_marginTop="10dp"
                    android:entries="@array/colori"
                    android:background="@drawable/edittextcentro"
                    android:textSize="10dp"
                    android:theme="@style/SpinnerTheme"
                    android:textAlignment="center"
                    android:textColor="@color/scuro"
                    android:prompt="@string/colorescelta"
                    android:spinnerMode="dropdown"/>

I want to set all these texts with the same non-default font.


Solution

  • You can do it by-:

    Just make a different layout my_layout-

    <Textview
       fontFamily="your font family"
    
    </Textview>
    

    and just change the code from-:

     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.colori, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    

    to-:

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.colori, R.layout.my_layout);
        adapter.setDropDownViewResource(R.layout.my_layout);