Key: the Spinner

Start by adding the dropdown option content to strings.xml

Post code:

<resources>
    <string name="app_name">First</string>
    <string-array name="inArray">
        <item>1</item>
        <item>2</item>
        <item>3</item>
    </string-array>

</resources>

Copy the code

Next we need to introduce tabs into the layout

Post code:


<Spinner
    android:id="@+id/inArray"
    android:layout_width="85dp"
    android:layout_height="30dp"
    android:gravity="center|right"
    android:layout_marginLeft="5dp"
    android:background="@drawable/whitesmoke"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>

Copy the code

Finally, write Java code

Post code:

public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DensityUtils.setDensity(getApplication(),this); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.activity_main); Spinner spinner=findViewById(R.id.inArray); ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(getApplicationContext(),R.array.inArray, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<? > parent, View view, int position, long id) { Toast.makeText(MainActivity.this,"position:"+position,Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView<? > parent) { } }); }}Copy the code

It’s over from there.