Toolbar的setTitle问题

移动开发 码拜 8年前 (2016-03-27) 1210次浏览
在setSupportActionBar(toolbar)之后调用toolbar.setTitle()的话。
在onCreate()中调用无效。
在onStart()中调用无效。
在onResume()中调用有效。
问一下这个是什么原因,研究了好久实在没找到。求高手详解。好人一生平安。
解决方案

40

从stackOverFlow的答案中:
The internal implementation of the support library just checks if the Toolbar has a title (not null) at the moment the SupportActionBar is set up. If there is, then this title will be used instead of the window title. You can then set a dummy title while you load the real title.
mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
mActionBarToolbar.setTitle(“”);
setSupportActionBar(mActionBarToolbar);
later…
mActionBarToolbar.setTitle(title);
地址:http://stackoverflow.com/questions/26486730/in-android-app-toolbar-settitle-method-has-no-effect-application-name-is-shown
写在onStart里面,当程序挂起的时候再次进入,应该是能看到title的。
但是第一次是没有看到,或许可以推测能否有库对flag进行判断第一次进入的时候就不进行某些操作了,原因是第二次进入的时候已经有设置了的title了,所以就直接进行了调用。
(仅为推测,具体不知库是怎么实现的)

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Toolbar的setTitle问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)