0

I'm new to Android development, so sorry if this is a stupid question. I have disabled Action Bar in AndroidManifest.xml like this android:theme="@style/AppTheme.NoActionBar" but I'm in need of Action Bar in a certain activity. How do I create and set new Action Bar only to that activity?

Edit: I forgot to mention that the activity I want to have an Action Bar is child of the activity with no Action Bar. I guess this causes the problems.

B. Hurray
  • 382
  • 4
  • 16
  • Possible duplicate of [Apply a theme to an activity in Android?](http://stackoverflow.com/questions/19125163/apply-a-theme-to-an-activity-in-android) – Mike M. Oct 16 '16 at 13:52

5 Answers5

1

Define the theme for that perticular activity in the menifest.

<activity
android:theme="@style/AppTheme.NoActionBar"
>
Gurpreet Kaur
  • 434
  • 1
  • 4
  • 16
1

The best way is for this problem

<activity android:name=".MainActivity"  android:theme="@style/AlertDialog.AppCompat.Light" android:label="activity_with_actionbar" />

And

    <activity android:name=".SecondActivity"  android:theme="@style/Theme.AppCompat.NoActionBar" android:label="activity_with_no_actionbar" />
Muhammad Jamal
  • 442
  • 4
  • 21
0

You can do the opposite, i.e., In AndroidManifest keep theme as android:theme="@style/AppTheme"

and in Activities that you dont want to see ActionBar, add below code in its onCreate method:

getSupportActionBar().hide();
Firoz Memon
  • 4,282
  • 3
  • 22
  • 32
0

Add theme specifically for each activity inside manifest

<activity
    android:name=".MainActivity"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
  </activity>
Rissmon Suresh
  • 13,173
  • 5
  • 29
  • 38
0

You can create a custom Action bar. And implement ActionBar class in the activity u needed to have an action bar. Its very easy way to do what you want. Follow this tutorial.

EA Rashel
  • 167
  • 2
  • 9