如何将拆分操作栏添加到我现有的代码中

时间:2013-10-26 05:29:29

标签: android android-actionbar

我想将分割actionbar添加到显示在屏幕顶部的现有actionbar,以便我可以在底部显示这些标签

ActionBar ab;
ab = getSupportActionBar();
ab.setDisplayShowHomeEnabled(false);
ab.setDisplayShowTitleEnabled(false);
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);


Tab tab = ab
        .newTab()
        .setIcon(R.drawable.ic_ab_dialpad)
        //.setText("DialPad")
        .setTabListener(new MyTabListener<DialerFragment>(this, "DialPad",
                DialerFragment.class));
ab.addTab(tab);

tab = ab
        .newTab()
        .setIcon(R.drawable.ic_ab_history_holo_dark)
        //.setText("Recents")
        .setTabListener(new MyTabListener<CallLogListFragment>(this, "Recents",
                CallLogListFragment.class));
ab.addTab(tab);

/*tab = ab
        .newTab()
        .setIcon(R.drawable.ic_contacts)
        //.setText("Contacts")
        .setTabListener(new MyTabListener<ContactListFragment>(this, "Contacts",
                ContactListFragment.class));
ab.addTab(tab);*/

/*tab = ab
        .newTab()
        .setIcon(R.drawable.ic_services)
        //.setText("Services")
        .setTabListener(new MyTabListener<ServicesFragment>(this, "Services",
                ServicesFragment.class));
ab.addTab(tab);*/

tab = ab
        .newTab()
        .setIcon(R.drawable.ic_voicemail)
        //.setText("Settings")
        .setTabListener(new MyTabListener<VoiceMailFragment>(this, "Settings",
                VoiceMailFragment.class));
ab.addTab(tab);

目前,这些标签位于顶部。如何将其分成actionbar? 我想在底部显示这些主要标签,在顶部显示另外两个标签

1 个答案:

答案 0 :(得分:0)

添加

uiOptions="splitActionBarWhenNarrow" 

如果API版本为14或更高,您要在活动标记内部拆分操作栏

否则添加

<meta-data android:name="android.support.UI_OPTIONS"
                   android:value="splitActionBarWhenNarrow" /> 
如果API版本低于14,则在<activity> and </activity>

例如:

   <manifest ...>
    <activity uiOptions="splitActionBarWhenNarrow" ... >
        <meta-data android:name="android.support.UI_OPTIONS"
                   android:value="splitActionBarWhenNarrow" />
    </activity>
</manifest>

here是如何拆分操作栏的指南。