【问题标题】:AutocompleteTextView text is not visibleAutocompleteTextView 文本不可见
【发布时间】:2012-06-04 10:23:48
【问题描述】:

在我从建议列表中选择一个项目后,在我的 AutoCompleteTextView 中文本不可见。我试过 setTextColor(android.R.color.black) 但它不起作用。我在清单中使用 Theme.Light。有人知道我能做什么吗?

谢谢,提前

蒂齐亚诺

【问题讨论】:

  • 更改文本颜色并查看setTextColor(android.R.color.white)
  • 背景是白色的,所以什么都不会发生
  • 资源 res = getResources(); int color = res.getColor(android.R.color.black);
  • 感谢您的回答,但我发现这不是文本颜色错误的问题。问题是视图的对齐方式,我将其设置为 AlignParentRight true,删除此规则后,文本可见。很抱歉浪费您的时间!
  • 我用actv对布局进行了一些更改后,文本又看不到了,我不知道为什么! Dheeresh Singh 的解决方案有效!

标签: android autocompletetextview


【解决方案1】:

请尝试

Resources res = getResources(); 
int color = res.getColor(android.R.color.black);
setTextColor(color )

http://sree.cc/google/android/defining-custom-colors-using-xml-in-android

【讨论】:

    【解决方案2】:

    使用 android.R.layout.select_dialog_item 而不是 android.R.layout.simple_dropdown_item_1line,它会正常工作。

    【讨论】:

      【解决方案3】:

      创建自定义布局 my_dropdown_item.xml:

      <TextView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@android:id/text1"
            style="?android:attr/spinnerDropDownItemStyle"
            android:singleLine="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="40dip"
            android:ellipsize="marquee"
            android:textColor="#000000"/>
      

      然后使用它:

      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.my_dropdown_item, YOURARRAY);
      

      【讨论】:

        【解决方案4】:

        一切都会好的:

        adapter = new ArrayAdapter<String>(getApplicationContext(),
                    android.R.layout.simple_dropdown_item_1line, string_resource);
            Resources res = getResources();
            int color = res.getColor(android.R.color.black);
            autoCompleteTextView.setTextColor(color);
        
            autoCompleteTextView.setAdapter(adapter);
        

        【讨论】:

          【解决方案5】:

          didldum 回答 https://code.google.com/p/android/issues/detail?id=5237

          通过扩展主题并覆盖键入文本和建议文本的 2 种样式的解决方法:

          在清单中使用扩展主题:... ...

          创建使用固定样式的新主题 (res/values/themes.xml):... @style/AutoCompleteTextViewLight @style/Widget.DropDownItemLight ...

          创建固定颜色的样式(res/values/styles.xml):... @android:color/primary_text_light @android:color/primary_text_light

          【讨论】:

            【解决方案6】:

            一种更简单的方法,只需将 AutoCompleteTextView 的背景颜色设置为白色。像这样:android:background="@android:color/white"

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2015-04-02
              • 2017-08-25
              • 2021-02-21
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多