我正在尝试设置操作栏列表导航的样式,使其在关闭状态下具有白色文本。但是,当我这样做时,它已将所有 文本变成白色,这不适用于白色下拉菜单。
有没有办法分别设置每个样式?文档不存在 :(
最佳答案
为您的适配器
添加自定义布局。在此我创建了一个布局,其中添加了一个 TextView
。使用 text color
和 background color
。
并像这样设置一个适配器:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.my_spinner_style, R.id.textView1,
COUNTRIES);
这里
R.layout.my_spinner_style
是我的自定义布局。
R.id.textView1
是来自 my_spinner_style.xml
的 TextView ID。
您还可以在 TextView 中应用您的 awn 样式。检查 this和 this文章。
检查这段代码:
在 onCreate
中:
/** Create an array adapter to populate dropdownlist */
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.my_spinner_style, R.id.textView1,
COUNTRIES);
/** Enabling dropdown list navigation for the action bar */
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
/** Defining Navigation listener */
ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition,
long itemId) {
Toast.makeText(getBaseContext(),
"You selected : " + COUNTRIES[itemPosition],
Toast.LENGTH_SHORT).show();
return false;
}
};
/**
* Setting dropdown items and item navigation listener for the actionbar
*/
getActionBar().setListNavigationCallbacks(adapter, navigationListener);
my_spinner_style.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFF00" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
关于android - 操作栏下拉打开和关闭项目样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15824793/