如何更改标签导航的位置?

How to change position of Tab Navigation?

我目前有基于选项卡的应用程序,选项卡位于底部。有什么办法可以放上去吗?

Add Tabs To Action Bar

要使用 ActionBar 创建选项卡,您需要启用 NAVIGATION_MODE_TABS,然后创建多个 ActionBar.Tab 实例并为每个实例提供 ActionBar.TabListener 接口的实现。例如,在你的 activity 的 onCreate() 方法中,你可以使用类似这样的代码:

    @Override
    public void onCreate(Bundle savedInstanceState) {
     final ActionBar actionBar = getActionBar();
    // Specify that tabs should be displayed in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create a tab listener that is called when the user changes tabs.
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
                // show the given tab
        }

        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
                // hide the given tab
        }

        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
                // probably ignore this event
        }
    };

    // Add 3 tabs, specifying the tab's text and TabListener
    for (int i = 0; i < 3; i++) {
        actionBar.addTab(actionBar.newTab().setText("Tab " + (i + 1)).setTabListener(tabListener));
    }
}

如何处理 ActionBar.TabListener 回调以更改选项卡取决于您构建内容的方式。但是,如果您使用 ViewPager 为每个选项卡使用片段,如上所示,则下一节将展示如何在用户选择选项卡时在页面之间切换,以及如何在用户在页面之间滑动时更新所选选项卡。

完整指南Check this out

希望对您有所帮助。