Neha Sharma Neha Sharma - 3 years ago 223
Android Question

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

Answer Source

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>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download