-2

I'm working on the "design" of an application we created for a school project. How can I change the design (text size, text color, color of the spinner etc.)of a spinner on Android Studio?

This is my code :

public class MainActivity extends AppCompatActivity {

    private String flowerSpinnerValue, modeSpinnerValue;
    private Flower flower;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Spinner flowerSpinner = (Spinner) findViewById(R.id.flowerSpinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.flowers_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        flowerSpinner.setAdapter(adapter);
        flowerSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (flowerSpinner.getSelectedItem().equals("Basil")) {
                    flower = new Basil();
                }

                if(flowerSpinner.getSelectedItem().equals("Mint")) {
                    flower = new Mint();
                    System.out.println("jusia");
                }
                if (flowerSpinner.getSelectedItem().equals("Thyme")) {
                    flower = new Thyme();
                }
            }

<Spinner
        android:id="@+id/flowerSpinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/ChooseFlower"
        android:layout_toEndOf="@+id/ChooseFlower"
        android:layout_toRightOf="@+id/ChooseFlower"
        android:backgroundTint="?android:attr/actionMenuTextColor"
        android:keepScreenOn="false"
        android:splitMotionEvents="false"
        android:textAlignment="center"
        android:visibility="visible" />

I think I should change something in my XML code but I don't know what. Thanks for your help !

Szcxx
  • 1
  • 5
    Possible duplicate of [How to change spinner text size and text color?](https://stackoverflow.com/questions/9476665/how-to-change-spinner-text-size-and-text-color) – Harsh Patel Jun 06 '17 at 11:24
  • 1
    Please search on stackoverflow before you ask a question – Harsh Patel Jun 06 '17 at 11:25

1 Answers1

0

this is working for me

    String[] columns = new String[] {DatabaseAdapter.ACTIVITYTYPE};
    int[] to = new int[] {R.id.tvSpin};
    final SimpleCursorAdapter mAdapter1 = new SimpleCursorAdapter(this, R.layout.spin_text, location_cursor, columns1, to1);
    mAdapter1.setDropDownViewResource(R.layout.drop_down_view);
    spinner.setAdapter(mAdapter1);

drop_down_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

     <TextView
        android:id="@+id/tvSpin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:layout_gravity="center|left"
        android:paddingLeft="10dp"
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="@color/BGo"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        />


</LinearLayout>

spin_text.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:orientation="horizontal"
     >

        <TextView
            android:id="@+id/tvSpin"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Doctors Name"
            android:textColor="@color/Black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_Product1"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Product1"
            android:textColor="@color/Black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_Product2"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Product2"
            android:textColor="@color/Black"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/tv_Product3"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Product3"
            android:textColor="@color/Black"
            android:textSize="12sp" />

         <TextView
            android:id="@+id/tv_Product4"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Product4"
            android:textColor="@color/Black"
            android:textSize="12sp" />

          <TextView
            android:id="@+id/tv_Product5"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:gravity="center"
            android:text="Product5"
            android:textColor="@color/Black"
            android:textSize="12sp" />

    </LinearLayout>
</LinearLayout>
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39