0

I need create spinner programmatically. I add spinner to linearLayout, its work but I don't know how chache designe it.

Example, I have this:

enter image description here

How remove it?(highlighted in red)

And how remove spinner text to center?

enter image description here

My xml

LinearLayout spinnerL add this my spinner

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/spinnerL"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="20dp"
        />

</RelativeLayout>

and main class

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


        // Array of choices
        View linearLayout =  findViewById(R.id.spinnerL);

        ArrayList<String> list = new ArrayList<String>();
        list.add("one");
        list.add("two");

        Spinner spinner = new Spinner(this);
        //Make sure you have valid layout parameters.

        spinner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

        ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,
                android.R.layout.simple_spinner_dropdown_item, list);
        spinner.setAdapter(spinnerArrayAdapter);

        ((LinearLayout) linearLayout).addView(spinner );
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
jikazali
  • 99
  • 2
  • 9

1 Answers1

0
  1. To remove small triangle, simplest method is to set background drawable, for example:

    spinner.setBackgroundResource(android.R.drawable.btn_default);

  2. To align text center, you need to create layout for spinner, see examples

Community
  • 1
  • 1
Max77
  • 1,466
  • 13
  • 19