我想在夏洛克操作栏中左侧的微调器,但由于标准行为,它出现在右侧。[见附图
如何解决?
好的,我已经通过使用导航列表而不是在 menu.xml 中手动添加微调器来做到这一点:
1.列表中需要的项目必须在array.xml中定义为:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="dashboardItemList">
<item>Dashboard</item>
<item>Downloads</item>
<item>Revenues</item>
<item>Ads</item>
<item>Rankings</item>
<item>Reviews</item>
<item>Events</item>
</string-array>
</resources>
2.在createMenuOption上调用navigationList方法
@覆盖
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main_menu, menu);
setNavigationList();
return super.onCreateOptionsMenu(menu);
}
3. 定义 NavigationMethod,从 array.xml 中获取字符串数组。并为 NavigationMode 设置内置布局 sherlock_spinner_dropdown_item。
public void setNavigationList() {
arrayItemsForDropdown = getResources().getStringArray(R.array.dashboardItemList);
Context context = getSupportActionBar().getThemedContext();
ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context,R.array.dashboardItemList, R.layout.sherlock_spinner_item);
list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setListNavigationCallbacks(list, this);
}
** 4. 现在根据您在 onNavigationItemSelected 方法中的选择给出实现 **
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
if (arrayItemsForDropdown[itemPosition].equals("Dashboard")) {
downloadIcon.setVisible(false);
DashboardFragment dashboardFragment = new DashboardFragment();
showFragment(R.id.fragmentContainer, dashboardFragment, "dashboard");
overridePendingTransition(R.anim.right_in, R.anim.right_out);
} else if (arrayItemsForDropdown[itemPosition].equals("Downloads")) {
Log.d("Spinner", "downloadClicked");
showProgressDialog();
new Thread(new Runnable() {
public void run() {
checkDownloadsData();
}
}).start();
}
// skipping further else parts.....
return true;
}
:) 默认情况下,导航列表在 ActionBarSherlock 中向左对齐。检查快照。