Can action bar contain PagerSlidingTabStrip?

24 Views Asked by At

I am using Android studio 3.3 canary 8 and my API level is 28. I have an activity which has the action bar and another PagerSlidingTabStrip. The action bar has a title and a close button to go home. Now, I want to get rid of these two toolbars and one toolbar either the action bar or the tabstrip, but I want the close button and the tabs as well. Can the action bar contain tabs? Or can I include the close button in the tabstrip anyhow? If it is not possible then can I do any trick to have something like this? The relevant part of my activity is here:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info);

        ViewPager viewPager = findViewById(R.id.viewPager);
        InfoFragmentPagerAdapter adapter = new InfoFragmentPagerAdapter(getSupportFragmentManager());

        adapter.addFragment(new InfoAboutFragment (), getString(R.string.about));
        adapter.addFragment(new InfoHelpFragment(), getString(R.string.help));

        PagerSlidingTabStrip tabsStrip = findViewById(R.id.tabs);
        tabsStrip.setViewPager(viewPager);

        tabsStrip.setShouldExpand(true);
        tabsStrip.setAllCaps(true);
        tabsStrip.setTextColor(Color.WHITE);
        tabsStrip.setDividerColor(Color.TRANSPARENT);
        tabsStrip.setDividerPadding(20);
        tabsStrip.setIndicatorColor(Color.WHITE);
        tabsStrip.setIndicatorHeight(12);
        tabsStrip.setUnderlineColor(Color.TRANSPARENT);

        setupActionBar();
    }


    private void setupActionBar() {
        getLayoutInflater().inflate(R.layout.toolbar, findViewById(android.R.id.content));
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        if (getSupportActionBar() != null) {
            getSupportActionBar().setTitle(R.string.about);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
            getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_36dp);
        }
    }
0

There are 0 best solutions below