Abhilash Kumar Abhilash Kumar - 2 months ago 10
Android Question

How to add action bar to second activity but not to first one

I have two activities, First is simple Login page in which I disabled action bar as I don't need it there, second activity is the user feed section where I want to add action bar with text or search option and app drawer maybe. How do I add the action bar to second activity but not to first?

Answer

You should make app theme like this to have no actionbars by default.

 <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorPrimary</item>
</style>

In your AndroidManifest.xml file, in <application> tag add this line:

android:theme="@style/AppTheme"

And if you need action bar on some activity just add this to your activity layout file:

   <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="owo.owocar.driver.rides_history_entity.ui.HistorySingleActivity">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:background="@drawable/gradient"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"

            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <include layout="@layout/content_history_single" />

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