0

I'm a beginner at programming in Android Studio and I'm developing a simple app for a school project. I'm using a "Maps Activity" layout and I added an action bar. I've also added some buttons, and I want to understand how to change the title on the action bar when I click a button.

Phantômaxx
  • 37,352
  • 21
  • 80
  • 110
UStBB
  • 39
  • 2

2 Answers2

1

You can achieve this via following code

getActionBar().setTitle("title");

write this line of code in action listener of the button.

Yousaf
  • 25,372
  • 4
  • 33
  • 58
0

you need this:

    public class MainActivity extends Activity{

    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                 getActionBar().setTitle(title);
                }
        });

          }

}
mohammadReza Abiri
  • 1,679
  • 1
  • 7
  • 20