简体   繁体   English

具有自定义布局选项卡的Android操作栏显示在栏的顶部而不是下方

[英]Android action bar with custom layout tabs show on top of bar not below

I have an action bar with a custom layout that seems to be interfering with how the tabs should layout. 我有一个带有自定义布局的操作栏,似乎在干扰选项卡的布局方式。 I think the problem is that since I'm using a custom view for the action bar when I try to add tabs it wants to put them "in" the action bar instead of below the action bar because of the custom layout. 我认为问题在于,由于我在尝试添加选项卡时使用操作栏的自定义视图,因此由于自定义布局,它希望将它们“放在”操作栏而不是在操作栏下方。 I want the tabs to be below like the would be if I used a regular menu in the action bar. 我希望选项卡位于下面,就像我在操作栏中使用常规菜单一样。

 LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflator.inflate(R.layout.menu_default, null);

    ActionBar actionBar = getActionBar();

    actionBar.setCustomView(v);

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    Tab t =  actionBar.newTab();
    t.setText("tab1");
    t.setTabListener(new TabListener() {

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }
    });

    actionBar.addTab(t);

    Tab t2 =  actionBar.newTab();
    t2.setText("tab2");
    t2.setTabListener(new TabListener() {

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }
    });

    actionBar.addTab(t2);

Action bar tabs go where the action bar wants to put them. 动作栏选项卡转到动作栏要放置它们的位置。 That may be "in" the action bar or below it, depending on screen size and orientation. 取决于屏幕的大小和方向,它可能在操作栏中或在操作栏中。 You do not have control over the matter. 您无法控制此事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM