AutoCompleteTextView设置白色 主题Theme_Light问题

本文介绍了解决AutoCompleteTextView在使用白色主题时出现下拉选项内容显示为白色的问题。通过修改AndroidManifest文件和创建自定义样式来调整下拉菜单文字颜色。



 在AutoCompleteTextView设置白色主题的时候 下拉的选项是白色的没有内容

解决办法

1. use an extended theme in your manifest:
...
<application android:theme="@style/Theme.Light.NoTitleBar.Workaround" ... >
...

2. create the new theme (res/values/themes.xml) which uses fixed styles:
...
	<style name="Theme.Light.NoTitleBar.Workaround" parent="@android:style/Theme.Light.NoTitleBar">
		<item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewLight</item>
		<item name="android:dropDownItemStyle">@style/Widget.DropDownItemLight</item>
	</style>
...

3. create the styles (res/values/styles.xml) which fix the color:
...
	<style name="AutoCompleteTextViewLight" parent="@android:style/Widget.AutoCompleteTextView">
		<item name="android:textColor">@android:color/primary_text_light</item>
	</style>
	<style name="Widget.DropDownItemLight" parent="@android:style/Widget.DropDownItem">
		<item name="android:textColor">@android:color/primary_text_light</item>
	</style>
Android开发中,如果你设置了`AutoCompleteTextView`的`android:dropDownHeight="wrap_content"`,你可以通过以下方法来获取下拉列表的高度: 1. **使用`getDropDownHeight()`方法**:这个方法可以直接获取到`AutoCompleteTextView`的下拉列表高度。 ```java AutoCompleteTextView autoCompleteTextView = findViewById(R.id.auto_complete_text_view); int dropDownHeight = autoCompleteTextView.getDropDownHeight(); ``` 2. **使用`getViewTreeObserver()`监听布局变化**:如果下拉列表的高度是动态变化的,你可以通过`ViewTreeObserver`来监听布局变化并获取高度。 ```java autoCompleteTextView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int dropDownHeight = autoCompleteTextView.getHeight(); // 在这里处理获取到的高度 autoCompleteTextView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); ``` 3. **使用`PopupWindow`的`getHeight()`方法**:由于`AutoCompleteTextView`的下拉列表是通过`PopupWindow`实现的,你可以通过反射获取`PopupWindow`的高度。 ```java try { Field popupField = AutoCompleteTextView.class.getDeclaredField("mPopup"); popupField.setAccessible(true); Object popup = popupField.get(autoCompleteTextView); if (popup instanceof ListPopupWindow) { ListPopupWindow listPopupWindow = (ListPopupWindow) popup; int dropDownHeight = listPopupWindow.getHeight(); // 在这里处理获取到的高度 } } catch (Exception e) { e.printStackTrace(); } ``` 通过上述方法,你可以获取到`AutoCompleteTextView`的下拉列表高度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值