How can I set the title programmatically
How can I set the current view title(by title I mean th开发者_如何学Goe text shown below battery & time(in the image below that would be "Menu Sample") programmatically? I found many examples using manifest file but none from code.
Activity.setTitle() - setTitle("My New Awesome Title!");
Like this
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.setTitle("This is my Title");
}
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.foo_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
or
youractivity.setTitle();
ActionBar actionBar = getActionBar();
actionBar.setSubtitle("mytest");
actionBar.setTitle("Hello");
** targetSdkVersion or minSdkVersion attribute is set to "11" or greater.
<manifest ... >
<uses-sdk android:minSdkVersion="11" ... />
...
</manifest>
I use this to change actionBar's text pragmatically in onCreate() method
getSupportActionBar().setTitle("yourString");
精彩评论