自动完成下拉列表中需要改变布局 [英] Autocomplete dropdown list needs layout change
问题描述
目前,我有我的应用程序自动完成下拉框,但它似乎字体颜色是一种灰色的,不可见的被填充列表时。第二图为当点击下拉的样子。我怎样才能改变布局的下拉菜单显示列表中的项目为不同的颜色,如黑色?
I currently have an autocomplete dropdown box on my app, but it appears the font color is a sort of grey and not visible when the list is being populated. The second picture shows how the dropdown looks when clicked. How can I change the layout for the dropdown to show the items in the list as a different colour like black?
下面!照片管理
AlertDialog.Builder adb = new AlertDialog.Builder(SettingsMain.this);
LayoutInflater inflater = SettingsMain.this.getLayoutInflater();
final View searchlayout = inflater.inflate(R.layout.search_friend, null);
friend_name = (AutoCompleteTextView) searchlayout.findViewById(R.id.friend_name);
friend_name.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable editable) {
}
public void beforeTextChanged(CharSequence charSequence, int arg1, int arg2, int arg3) {
}
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
String text = charSequence.toString();
new MyAsyncTask("get").execute("http://10.0.2.2/jamtivia/webservice.php?type=get_friends&username="+text);
drop_down_adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line,adapterList);
drop_down_adapter.notifyDataSetChanged();
friend_name.setAdapter(drop_down_adapter);
if (!friend_name.isPopupShowing()) {
friend_name.showDropDown();
}
for(int i =0;i < adapterList.size();i++)
Log.d("TEXT CHNGE", adapterList.get(i));
}
});
adb.setView(searchlayout)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String fname = friend_name.getText().toString();
Integer friend_id = null;
try{
friend_id = adapterListId.get(adapterList.indexOf(fname));
Log.d( "ECHO" , "text : " + name +"ID :"+ player_id+ " ID: " + friend_id);
String request = "http://10.0.2.2/jamtivia/webservice.php?type=add_friends&friendId="+friend_id+"&playerId="+player_id;
new MyAsyncTask("send").execute(request);
}catch(Exception e){Log.d( "PROBLEM SENDING" , "text : " + adapterList.indexOf(fname));}
return;
}
})
.setNegativeButton("Done", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
adb.show();
此外,至于你可以在这个片段中code的看到,这是开展这一功能的好办法?
Also, as far as you can see with this snippet of code, is this a good way to carry out this function?
推荐答案
在创建ArrayAdapter,而不是使用predefined布局使用您的自定义布局
While creating ArrayAdapter instead using the predefined layout use your custom layout
像这样
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cust_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:background="@drawable/list_style"
android:textSize="17sp"
android:padding="5dp"
android:gravity="left|center_vertical"/>
//你可以给你的选择,背景颜色或图片
并给起了个名字你的选择让我们说custom_list.xml
//you can give color or image of your choice as background and give a name as your choice let us say custom_list.xml
在创建适配器使用您的布局像这样
While Creating adapter use your layout like this
drop_down_adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.custom_list,adapterList);
我希望这会帮助你。
I hope this will help you
这篇关于自动完成下拉列表中需要改变布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!