AutoCompleteTextView前景/背景颜色 [英] AutoCompleteTextView background/foreground color
问题描述
我的工作AutoCompleteTextView.Its工作正常,但下拉文本始终是白色背景上的白色文字。 这张图说明我的问题。
图片说明我的问题。
XML:
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#000
>
<! - < AutoCompleteTextView - >
< AutoCompleteTextView
机器人:ID =@ + ID /文
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=Tapez您的评分1texte
机器人:文字颜色=#000
/>
< / LinearLayout中>
Java的:
查看=(AutoCompleteTextView)findViewById(R.id.text);
ArrayAdapter<字符串>适配器=新的ArrayAdapter<字符串>(这一点,android.R.layout.simple_dropdown_item_1line,数据);
adapter.setDropDownViewResource(R.drawable.ic_action_search); // DD
view.setAdapter(适配器);
如果你想改变的下拉列表项的外观改变你传递给一个ArrayAdapter的XML布局,(在你的情况,这是 android.R.layout.simple_dropdown_item_1line
)。
让我们使名为 my_list_item.xml
在 RES /布局
新的布局:
< TextView中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / text1中
风格=机器人:ATTR / dropDownItemStyle
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=中心
机器人:填充=5DP
机器人:textAppearance =机器人:ATTR / textAppearanceMediumInverse
机器人:文字颜色=#00F/>
这文字较小,蓝色和居中。我不建议使用这种布局,它更证明你可以自定义它。
现在用这个来代替:
查看=(AutoCompleteTextView)findViewById(R.id.text);
ArrayAdapter<字符串>适配器=新的ArrayAdapter<字符串>(这一点,R.layout.my_list_item,数据);
view.setAdapter(适配器);
在这里设置属性(如文本颜色):
< AutoCompleteTextView
机器人:ID =@ + ID /文
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=Tapez您的评分1texte
机器人:文字颜色=#000
/>
您只更改上面的下拉列表中(也就是说你看到你之前用AutoCompleteTextView交互箱)箱。希望帮助!
I am working on AutoCompleteTextView.Its working fine but the dropdown text is always white text on white background. this picture explain my problem
picture explain my problem
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000"
>
<!-- <AutoCompleteTextView -->
<AutoCompleteTextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Tapez votre 1texte"
android:textColor="#000"
/>
</LinearLayout>
Java:
view = (AutoCompleteTextView)findViewById(R.id.text);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,data);
adapter.setDropDownViewResource(R.drawable.ic_action_search);//dd
view.setAdapter(adapter);
If you want to change the look of the dropdown items change the XML layout you pass to the ArrayAdapter, (in your case this is android.R.layout.simple_dropdown_item_1line
).
Lets make a new layout named my_list_item.xml
in res/layout
:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/dropDownItemStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMediumInverse"
android:textColor="#00f" />
This text is smaller, blue, and centered. I don't recommend using this layout, it's more to demonstrate that you can customize it.
Now use this instead:
view = (AutoCompleteTextView)findViewById(R.id.text);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.my_list_item, data);
view.setAdapter(adapter);
When you set attributes here (like the text color):
<AutoCompleteTextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Tapez votre 1texte"
android:textColor="#000"
/>
You are only changing the box above the dropdown list (the box that you see before you interact with the AutoCompleteTextView). Hope that helps!
这篇关于AutoCompleteTextView前景/背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!