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.
Asked
Active
Viewed 123 times
2 Answers
1
You can achieve this via following code
getActionBar().setTitle("title");
write this line of code in action listener of the button.

Yousaf
- 27,861
- 6
- 44
- 69
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,759
- 1
- 9
- 20