Change Actionbar title in older versions

Asked

Viewed 41 times

1

Hello I have four screens in my android app and I want in each screen the action bar has a different name. I tried to change the title using getActionBar().setTile():

inserir a descrição da imagem aqui

But since I have API 9 as a minimum version and can’t use it. There are some other options that work from API 9?

  • Denis, to facilitate the life of those who are responding, and indexing / search for answers, avoid pasting print screens code. It is always best to paste the code itself into the body of the question.

1 answer

3


For older versions you will need to use the method getSupportActionBar().

See that for this your class will have to inherit from ActionBarActivity or AppCompatActivity or instead of Activity:

public class MinhaAtividade extends ActionBarActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setTitle("Meu titulo");            
        setContentView(R.layout.activity_minha_tela);
    }

    // ... demais métodos
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.