How to define a different title for each screen in Android Studio 2.3.3?

0

I recently bought an application, and I am still modifying it, but I can not change the title of the action bar (not for the main one, but for each screen).

I am trying to change the title of the action bar for each activity (facebook, video, photos, etc.), that is, I want the user to enter the photo section the action bar change from the main title to the title of the activity (Photos).

I do not know if I explain, I'm a novice in all this. Thank you very much for your time.

    
asked by Axl Cruz 06.01.2018 в 15:35
source

1 answer

1

First create the string resource for the name of the activity in values / strings.xml

For example:

<string name="mi_titulo">Mi actividad</string>

You can change the title from java code, that is, dynamically or from the manifest:

From java code

public class MiActividad extends AppCompatActivity {

    String titulo= "mi_actividad";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.setTitle(R.string.mi_titulo);

    }
}

From the Manifest

In the manifest, you locate the activity whose title you want to change and add the label attribute with the new value:

<activity android:name=".tu_actividad"
            android:label="@string/mi_titulo"/>
    
answered by 06.01.2018 в 16:03