If all you want is to change the color of the notification bar when you change your activity, you just have to apply a different theme in each activity, which you can do from xml.
The first thing is to define the themes that you will use in the activities, they can be very similar topics in which you only change the color of the notification bar. The property that modifies this color is colorPrimaryDark
. The themes are defined in the styles.xml file.
<!--Thema por defecto-->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!--Tema de la SegundaActivity-->
<style name="ThemeSegundaActivity" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@android:color/holo_orange_light</item> <!--Color naranja-->
<item name="colorAccent">@color/colorAccent</item>
</style>
Then in the AndroidManifest.xml you assign a different theme to each activity.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="davidminaya.respuestasstackoverflow">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Respuestas Stack Overflow"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SegundaActivity"
<!--Con esta sentencia le asignas el tema a la actividad-->
android:theme="@style/ThemeSegundaActivity">
</activity>
</application>
</manifest>
In this case the color of the notification bar in the SecondActivity will be orange.
Keep in mind that if you do not assign a topic to the activity, the default theme of this is the theme of the application.