ActionBarSherlock:使用actionbarSherlock在左侧显示/移动微调器[解决方案:使用NavigationList]

时间:2012-12-07 09:05:46

标签: android android-actionbar actionbarsherlock

我想在sherlock操作栏的左侧使用微调器,但由于标准行为,它位于右侧。[请参阅附件图像]

如何解决?

1 个答案:

答案 0 :(得分:3)

好的,我通过使用导航列表而不是在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 Method **

中给出实现
@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;
}

:)导航列表bydefault在ActionBarSherlock中左对齐。检查快照。

enter image description here