繁体   English   中英

AutoCompleteTextView下拉样式被忽略

[英]AutoCompleteTextView dropdown style ignored

疯狂...无论我尝试什么,我的AutoCompleteTextView显示具有默认样式的下拉项目。 我似乎无法以任何方式访问下拉视图-我尝试使用XML进行样式设置,在我的适配器中对其进行编码以及对AutoCompleteTextView本身进行编码。

spinner_dropdown_item.xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:paddingLeft="10dp"
      android:paddingRight="10dp"
      android:paddingTop="15dp"
      android:paddingBottom="15dp"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textColor="#000"
      android:textSize="16dp"
    />

我的客户端( LoginFragment.java ):

AutoCompleteTextView user_name = (AutoCompleteTextView) layout.findViewById(R.id.user_name);

final MyAdapter<User> adapter = new MyAdapter<User>(my_activity, my_list);
//does nothing
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
//crashes app with no error or anything!
user_name.setDropDownBackgroundResource(R.layout.spinner_dropdown_item);

user_name.setAdapter(user_adapter);

最后,在我的适配器中,它可以完美地为任何微调器设置下拉菜单的样式,但无法为AutoCompleteTextView设置下拉菜单的样式:

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    TextView tv;
    if (convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
        tv = (TextView) inflater.inflate(R.layout.spinner_dropdown_item, null);
    } else {
        tv = (TextView) convertView;
    }
    T object = objects.get(position);
    String label = NULL_ITEM;
    if (object != null) {
        label = object.toString();
    }
    tv.setText(label);
    return tv;
}

如何更改AutoCompleteTextView中的下拉列表,以便对下拉文本项进行任何样式设置?

我似乎已找到问题所在。 我的Adapter类需要在其构造函数中接收所需的布局。 没有想法,为什么它不能在适配器本身中引用所需的布局

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM