In Android, the Spinner is the automatically displayed style of the drop-down menu and AutoCompleteTextView. It is equivalent to the <select> label in HTML.
The Spinner Widget drop-down menu and AutoCompleteTextView provided in Android are very easy to use and style is also applicable,
However, we can change the style of the drop-down menu by defining xml.
Create an xml file in the layout directory with the name (activity_main.xml ). You can define the style of the drop-down menu in this file.
TextView is used here.
Activity_main.xml:
View Code
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:background="#000000" 6 tools:context=".MainActivity" > 7 8 <AutoCompleteTextView 9 android:id="@+id/actv"10 android:layout_width="fill_parent"11 android:layout_height="wrap_content" />12 13 </RelativeLayout>
The custom style is to create an xml file under layout. The Code is as follows:
Down. xml:
View Code
1 <TextView xmlns:android="http://schemas.android.com/apk/res/android"2 xmlns:tools="http://schemas.android.com/tools"3 android:id="@+id/contentTextView"4 android:layout_width="fill_parent"5 android:layout_height="wrap_content"6 android:background="#F4FDFF"7 android:textColor="#000000" >8 9 </TextView>
The call method in the activity is as follows:
View Code
1 package com. example. autocompletetextvewtest; 2 3 import java. util. list; 4 5 import android. app. activity; 6 import android. OS. bundle; 7 import android. view. menu; 8 import android. widget. arrayAdapter; 9 import android. widget. autoCompleteTextView; 10 11 public class MainActivity1 extends Activity {12 private AutoCompleteTextView actv; 13 14 @ Override15 protected void onCreate (Bundle savedInstanceState) {16 super. onCreate (savedInstanceState); 17 setContentView (R. layout. activity_main); 18 String [] strings = new String [] {"Beijing", "Beijing West Station", "Beijing South Station", "Shanghai", "Shanghai Pudong Airport "}; 19 actv = (AutoCompleteTextView) findViewById (R. id. actv); 20 // The second parameter is the Layout id of the style, and the third parameter is: id21 ArrayAdapter <String> adapter = new ArrayAdapter <String> (this, 22 R. layout. down, R. id. contentTextView, strings); 23 actv. setThreshold (1); 24 actv. setAdapter (adapter); 25} 26 27 @ Override28 public boolean onCreateOptionsMenu (Menu menu) {29 getMenuInflater (). inflate (R. menu. activity_main, menu); 30 return true; 31} 32 33}
This is all done!