0

Following the tutorial here: http://www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html# trying to perform material design sliding tabs I did everything as instructed.

However, when I run the app it gave me the following message:

java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.

I tried to resolve this and tried many thing, with no success.

Eventually I came to this SO question stackoverflow.com/questions/29790070/upgraded-to-appcompat-v22-1-0-and-now-getting-illegalargumentexception-appcompa and took the answered suggestion.

I changed my styles.xml as follows:

<style name="AppBaseTheme" parent="Theme.AppCompat.NoActionBar">
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">

</style>

Nevertheless, it still gives me the same error message.

Just for the sake of completion, here is my Activity:

public class MainActivity extends AppCompatActivity {

    private ViewPager mViewPager;
    private HomeTabsPagerAdapter mPageAdapter;

    private Toolbar mToolbar;
    private SlidingTabLayout mTabs;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

                setContentView(R.layout.activity_main);

                setViewsClassMembers();

                setSupportActionBar(mToolbar);
                mPageAdapter = new HomeTabsPagerAdapter(getSupportFragmentManager());

                mViewPager.setAdapter(mPageAdapter);
                // Assiging the Sliding Tab Layout View
                mTabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width

                // Setting Custom Color for the Scroll bar indicator of the Tab View
                mTabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
                    @Override
                    public int getIndicatorColor(int position) {
                        return getResources().getColor(R.color.tabsScrollColor);
                    }
                });

                // Setting the ViewPager For the SlidingTabsLayout
                mTabs.setViewPager(mViewPager);

    }


    private void setViewsClassMembers() {
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mToolbar = (Toolbar) findViewById(R.id.tool_bar);
        mTabs = (SlidingTabLayout) findViewById(R.id.tabs);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()) {
        case R.id.action_new_request:
            startNewRequestActivity();
            break;
        }
        return super.onOptionsItemSelected(item);
    }

    private void startNewRequestActivity() {
        Intent intent = new Intent(this, NewRequestActivity.class);
        startActivity(intent);
    }

}

Can anyone see where is the problem? why do Android insists that I am already having action bar?

Community
  • 1
  • 1
dsb
  • 2,347
  • 5
  • 26
  • 43
  • "set windowActionBar to false in your theme to use a Toolbar instead" did you try that? – Tim Oct 21 '15 at 08:56
  • @TimCastelijns Yes, I have tried that and many other appears to be relevant features. When I set windowsActionBar to false I get "AppCompat does not support the current theme features" error message. The same guy from Android wrote on another SO question that AppCompat is now much stricter with the features it accepts. – dsb Oct 21 '15 at 09:12

1 Answers1

0

See it: https://stackoverflow.com/a/26515159

<item name="windowActionBar">false</item> 

inside your styles.xml.

Community
  • 1
  • 1
WangJie
  • 526
  • 3
  • 7
  • Thank you. I tried this and many other features. When I add this line to the styles.xml I get "AppCompat does not support the current theme features". – dsb Oct 21 '15 at 09:14