Nick
Nick

Reputation: 595

ActionBar background only works in portrait mode

I have this

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

        actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);



        mSectionsPagerAdapter = new SectionsPagerAdapter(this,
                getSupportFragmentManager());
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowHomeEnabled(false);

        actionBar.setStackedBackgroundDrawable(getResources().getDrawable(
                R.drawable.navbar_bg));

Why does the last line only work in portrait mode, in landscape mode no background is applied. I have not applied any custom orientation styles to the activity. Thank you

Upvotes: 0

Views: 281

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 200120

As per the Tabs Design document and the ActionBar Tabs guide:

the system adapts the action bar tabs for different screen sizes—placing them in the main action bar when the screen is sufficiently wide, or in a separate bar (known as the "stacked action bar") when the screen is too narrow

Therefore cases where the system decides to combine the bars (such as in landscape mode), the tabs will be part of the main Action Bar and share the same background as the Action Bar.

Upvotes: 1

Related Questions