[英]Set foreground and background color of JButton with JColorChooser
[英]AutoCompleteTextView background/foreground color
我正在使用AutoCompleteTextView.Its工作正常,但下拉文本始終是白色背景上的白色文本。 這張照片解釋了我的問題
圖片解釋我的問題
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);
如果要更改下拉項的外觀,請更改傳遞給ArrayAdapter的XML布局(在您的情況下,這是android.R.layout.simple_dropdown_item_1line
)。
讓我們在res/layout
創建一個名為my_list_item.xml
的新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" />
此文本較小,為藍色,居中。 我不建議使用此布局,它更多的是證明您可以自定義它。
現在改用它:
view = (AutoCompleteTextView)findViewById(R.id.text);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.my_list_item, data);
view.setAdapter(adapter);
在此處設置屬性(如文本顏色):
<AutoCompleteTextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Tapez votre 1texte"
android:textColor="#000"
/>
您只需更改下拉列表上方的框(您在與AutoCompleteTextView交互之前看到的框)。 希望有所幫助!
這個問題可能已經過時了,但我相信這對我來說非常重要。 我遇到了與OP相同的問題,但這是因為我使用'getApplicationContext()'代替'this'
錯誤
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(getApplicationContext(), android.R.layout.simple_list_item_1, PLACES);
正確
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, PLACES);
一個棘手的解決方案是:添加此行setTheme(android.R.style.Theme); 在存在autocompletetextview的活動文件中的setContentView()
之前。 讓我知道這個是否奏效。
回答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
我嘗試在setcontext之前設置主題,在arrayAdapter中嘗試了不同的資源參數並嘗試了不同的主題,但沒有任何幫助。
然后我將上下文從'this'更改為'getApplicationContext'但問題仍然存在。
最后我將context參數更改為“getBaseContext()”,問題解決了。
我在選擇“select_dialog_singlechoice ArrayAdapter<String > s1= new ArrayAdapter<String> (this,android.R.layout.select_dialog_singlechoice,state);
布局中得到了我的解決方案ArrayAdapter<String > s1= new ArrayAdapter<String> (this,android.R.layout.select_dialog_singlechoice,state);
在這里輸入圖像描述
而不是獲取應用程序上下文在ArrayAdapter <>中寫入“this”;
嘗試使用不同的布局,你肯定會解決你的疑問
我通過一個簡單的棘手的方式解決了這個問題,
只需將AndroidManifest.xml中聲明的活動主題更改為 ,
<activity
android:name=".YourActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:windowSoftInputMode="stateHidden"></activity>
並在活動中如下 ,
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(getActivity(), android.R.layout.select_dialog_item, arraylist);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.