This Activity already has an action bar supplied by the window decor?

I am making an Android app using Toolbar with Custom style but when i’m running the app, i’m getting the following error:

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

Styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:textColor">@color/textColorPrimary</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="android:textColorSecondary">@color/textColorPrimary</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

<style name="MyMaterialTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorPrimary</item>

</style>


<style name="MyEditTextTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Used for the bottom line when not selected / focused -->
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:colorBackground">@color/colorBackground</item>
    <item name="android:textStyle">bold</item>
    <item name="android:endColor">@color/colorPrimary</item>




    <!-- colorControlActivated & colorControlHighlight use the colorAccent color by default -->
</style>

<style name="TabTextAppearance" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:colorBackground">@color/colorBackground</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:textStyle">bold</item>
</style>

MainActivity:

public class MainActivity extends AppCompatActivity {

private TabLayout tabLayout;
private ViewPager viewPager;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_information_category1);
    Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar_information);
    setSupportActionBar(toolbar);

    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);


}

private void setupViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new TodayInformationFragment(), "Today");
    adapter.addFragment(new ThisWeekInformationFragment(), "This Week");
    adapter.addFragment(new ThisMonthInformationFragment(), "This Month");
    adapter.addFragment(new AllyearInformationFragment(), "All");
    viewPager.setAdapter(adapter);
}
class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }
}

}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)