Doubt with Toolbar on Android

0

I'm studying Android, but this doubt came to me.

Why when we add a Toolbar to an activity from its XML, we should then tell it to call "setSupportActionBar (toolbar);"?

In case I want to add a second Toolbar, do I have to call that method again?

The truth is that I'm not clear about that.

Greetings.

    
asked by Pablo Palma 26.12.2018 в 12:22
source

1 answer

0

I did not understand your question very well but if you do not know how to use a ToolBar, there's a little help:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater ().inflate ( R.menu.menu_toolbar, menu );
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId ();

    //noinspection SimplifiableIfStatement
    if (id == R.id.Cerrar) {
        fondo= new Fondo ();
        getSupportFragmentManager ().beginTransaction ().add ( R.id.content_main, fondo ).commit ();
        return true;
    }
    if(id==R.id.Scan){
        Intent intent = new Intent (getBaseContext (), Scanner.class);
        startActivity(intent);

    }


    return super.onOptionsItemSelected ( item );
}
// </editor-fold>

Data:

Remember that the current android brings you help, so it's easier to do it, otherwise the tutorials are very helpful:)

    
answered by 02.01.2019 в 16:45