简体   繁体   English

AutoCompleteTextView下拉样式被忽略

[英]AutoCompleteTextView dropdown style ignored

Madness...no matter WHAT I try, my AutoCompleteTextView shows drop down items with default styling. 疯狂...无论我尝试什么,我的AutoCompleteTextView显示具有默认样式的下拉项目。 I cannot seem to access the dropdown view in any way - I've tried styling in XML as well as coding it up in my Adapter as well as coding up the AutoCompleteTextView itself. 我似乎无法以任何方式访问下拉视图-我尝试使用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"
    />

My client ( LoginFragment.java ): 我的客户端( 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);

Finally, in my adapter, which is working perfectly to style drop down items for any spinner, but fails to style the drop down for AutoCompleteTextView: 最后,在我的适配器中,它可以完美地为任何微调器设置下拉菜单的样式,但无法为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;
}

How can I change the drop down list in an AutoCompleteTextView such that the dropdown text items are styled in any way at all? 如何更改AutoCompleteTextView中的下拉列表,以便对下拉文本项进行任何样式设置?

I seem to have located the problem. 我似乎已找到问题所在。 My Adapter class needed to receive the desired layout in its constructor. 我的Adapter类需要在其构造函数中接收所需的布局。 No IDEA why it couldn't reference the desired layout in the adapter itself 没有想法,为什么它不能在适配器本身中引用所需的布局

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

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