How to change spinner text size in android programmatically

How to increase decrease spinner inside text items font size look bigger or smaller in android app.

Spinner text size are called as spinner inside items font size which is easily changeable if we are setting up textview items all we have do is defining text size in textview layout xml. So here is the complete step by step tutorial for How to change spinner text size in android programmatically.

android-project-download-code-button

How to change spinner text size in android programmatically.

Code for MainActivity.java file.

 package com.changespinnertextsize_android_examples.com;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class MainActivity extends Activity {

 Spinner spinnerFontChange;
 
 String[] spinnerItems = new String[]{
 "APPLE",
 "MANGO",
 "BANANA",
 "PAPAYA",
 "WATER MELON",
 
 };
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 spinnerFontChange = (Spinner)findViewById(R.id.spinner1);
 
 ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
 this,R.layout.textview_with_font_change,spinnerItems );
 
 spinnerArrayAdapter.setDropDownViewResource(R.layout.textview_with_font_change);
 
 spinnerFontChange.setAdapter(spinnerArrayAdapter);
 
 spinnerFontChange.setOnItemSelectedListener(new OnItemSelectedListener() {

 @Override
 public void onItemSelected(AdapterView<?> parent, View view,
 int position, long id) {
 // TODO Auto-generated method stub
 
 Toast.makeText(MainActivity.this, spinnerFontChange.getSelectedItem().toString(), Toast.LENGTH_LONG).show();
 
 }

 @Override
 public void onNothingSelected(AdapterView<?> parent) {
 // TODO Auto-generated method stub
 
 }
 });
 
 }
}

Code for activity_main.xml layout file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.changespinnertextsize_android_examples.com.MainActivity" >

 <Spinner
 android:id="@+id/spinner1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true" />

</RelativeLayout>

Code for textview_with_font_change.xml.

 <?xml version="1.0" encoding="utf-8"?>
 <TextView
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:textColor="#000301"
 android:padding="10dp"
 android:textSize="20dp" />

Screenshot:

How to change spinner text size in android programmatically

Click here to download How to change spinner text size in android programmatically project.

Leave a Reply

Your email address will not be published. Required fields are marked *