我知道在Android Activity
中设置标题有两种方法。
假设我已经有了下面的代码...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
...
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(toolbar);
我可以使用这个或者那个...
getSupportActionBar().setTitle("My title");
...对于这个问题...
toolbar.setTitle("My title");
...设置我的标题。
我的问题是,哪种做法更好?
setSupportActionbar(toolbar).setTitle(R.string.title);
但是我们甚至不能setSupportActionbar(toolbar.setTitle(R.string.title));
。 - J.G.Sebring