我想样式操作栏列表导航,使得它具有在关闭状态下的白色文本。 当我这样做,但是,它已经把所有的文白,不与白色的下拉工作。
有没有办法单独样式每个? 该文档是不存在的:(
我想样式操作栏列表导航,使得它具有在关闭状态下的白色文本。 当我这样做,但是,它已经把所有的文白,不与白色的下拉工作。
有没有办法单独样式每个? 该文档是不存在的:(
添加自定义布局的Adapter
。 在这方面,我已创建了一个布局里面,我有添加一个TextView
。 与text color
和background color
。
并设置atapter这样的:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.my_spinner_style, R.id.textView1,
COUNTRIES);
这里
R.layout.my_spinner_style
是我的自定义布局。
R.id.textView1
是TextView的ID my_spinner_style.xml
。
你也可以applay内部的TextView您芒风格。 检查这个和这个 aretical。
检查这个代码:
里面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>
也许,你可以通过编程(虽然我从来没有尝试过)做到这一点:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menuId, menu);
menu.findItem(R.id.itemId).getActionView().setBackground(...)
}
如果您使用的Adapter
(必须由定义实现SpinnerAdapter
)你有两个回调,你可以重写。 getView
将称其为“选择”的项目。 getDropDownView
将被调用为下拉项。 你可以有你的设置不同的文本颜色。