【问题标题】:AutoCompleteTextView dropdown style ignoredAutoCompleteTextView 下拉样式被忽略
【发布时间】:2013-03-16 18:01:52
【问题描述】:

疯狂...无论我尝试什么,我的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 中的下拉列表,以便下拉文本项以任何方式设置样式?

【问题讨论】:

    标签: android android-arrayadapter autocompletetextview


    【解决方案1】:

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

    【讨论】:

    • 你好,我遇到了和你完全相同的问题:(你所说的“我的适配器类需要在其构造函数中接收所需的布局”是什么意思?我可以看看你的代码,或者你能不能在你的答案中添加你的代码?
    猜你喜欢
    • 2014-01-01
    • 1970-01-01
    • 2016-07-24
    • 2018-08-04
    • 1970-01-01
    • 1970-01-01
    • 2020-05-01
    • 2015-12-21
    • 1970-01-01
    相关资源
    最近更新 更多