Neha Sharma
Neha Sharma

Reputation: 83

Do not request Window.FEATURE_SUPPORT_ACTION_BAR

I have a LoginActivityclass(TabActivity) which have following code to cover whole mobile screen

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        FacebookSdk.sdkInitialize(getApplic

Now I want to go to another MainActivityclass(AppCompatActivity) using Intent which have toolbar. Its code is-

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

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

XML-

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        app:contentInsetRight="@dimen/fab_margin"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

It is working fine while I am not opening MainClass using Intent, but I want t o open MainActivityClass there is an error -

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.......

Upvotes: 1

Views: 11507

Answers (2)

VBage Tech
VBage Tech

Reputation: 1

This error occurs by many mistakes I have listed below some Situations :

1.) If you have not created Toolbar in your layout

2.) If you are using

android:theme="@style/AppTheme.NoActionBar"

Theme and try to get Actionbar.

3) if you have not

extends AppCompatActivity

Upvotes: 0

rafsanahmad007
rafsanahmad007

Reputation: 23881

try this:

in manifest

// the activity where you want to show `toolbar`
    <activity android:name=".YourActivity"  
     android:theme="@style/AppTheme.NoActionBar"><!-- ADD THIS LINE -->

in styles.xml

<style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
</style>

add this android:theme="@style/Theme.AppCompat.Light" to your application tag in the Manifest file

<application
        android:theme="@style/Theme.AppCompat.Light"
</application>

Upvotes: 8

Related Questions