Editing text in action bar

2019-07-09 02:39发布

问题:

I am using Action Bar Sherlock to create the UI for my app. Upon adding the dependencies to my project and such forth I created an activity to test it out.

public class PPS extends SherlockActivity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.activity_main, menu);
    return true;
}

}

I am trying to change the title of action bar however I am not sure on how to do this. When I checked the activity_main thats all I saw, no element to change the text in the activity.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

So how do you change the text in the action bar?

回答1:

In the onCreate():

this.getActionBar().setTitle("your title here");