Search code examples
androidandroid-studioandroid-activityandroid-actionbar

Android how to set ActionBar in just one Activity


I am new to Android and I'm facing this problem. I got MainActivity with items list, when one of them is clicked then the DetailActivity starts.

I disabled ActionBar with

<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">

so the MainActivity no longer have actionBar. But I want this ActionBar in the DetailActivity ( i need the basic one, with the left arrow to get back to MainActivity ), so I created another style

<style name="DetailTheme" parent="android:Theme.Material.Light.DarkActionBar">

and used it in activity_detail.xml like this android:theme="@style/DetailTheme"

But it seems this is not the right way, because there is no ActionBar in that Activity .

I'm currently not sure if DetailActivity will be the only one with ActionBar, so I would like to know how to activate it on just this one Activity. What is the right solution for this ?


Solution

  • Not sure but maybe try assigning it to the activity in the manifest

    <activity android:name=".DetailActivity"
                android:theme="@style/DetailTheme"/>