您可以将箭头图像添加为drawable-right / drawable-end。设置可聚焦属性和光标可见性为false,单击“编辑”文本打开带列表的对话框。对于后台使用相同的背景,您使用的是电子邮件地址edittext。以下是示例XML代码
<EditText
android:id="@+id/etCustomerType"
android:layout_width="match_parent"
android:layout_height="@dimen/_40sdp"
android:layout_marginStart="@dimen/_15sdp"
android:layout_marginEnd="@dimen/_15sdp"
android:backgroundTint="@color/editTextTextColor"
android:cursorVisible="false"
android:drawableEnd="@drawable/ic_dropdown"
android:drawableRight="@drawable/ic_dropdown"
android:drawablePadding="@dimen/_10sdp"
android:focusable="false"
android:focusableInTouchMode="false"
android:paddingStart="@dimen/_10sdp"
android:paddingEnd="@dimen/_10sdp"
android:textColor="@color/editTextTextColor"
android:textColorHint="@color/editTextTextColor"
android:textCursorDrawable="@color/editTextTextColor"
android:textSize="@dimen/textSizeXSmall" />
我想这应该做:
XML文件应该是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<AutoCompleteTextView
android:id="@+id/sex"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></AutoCompleteTextView>
</LinearLayout>
而MainActivity.java
应该是
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends Activity {
String[] sex = { "Male", "Female" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Create Array Adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.select_dialog_singlechoice, sex);
//Find TextView control
AutoCompleteTextView acTextView = (AutoCompleteTextView) findViewById(R.id.sex);
//Set the number of characters the user must type before the drop down list is shown
acTextView.setThreshold(1);
//Set the adapter
acTextView.setAdapter(adapter);
}
}