android - how to pin title in Toolbar inside CollapsingToolbarLayout -
here layout:
<android.support.design.widget.appbarlayout <android.support.design.widget.collapsingtoolbarlayout ... <android.support.v7.widget.toolbar ... /> </android.support.design.widget.collapsingtoolbarlayout> </android.support.design.widget.appbarlayout>
i want title stays in toolbar, not in collapsingtoolbarlayout. changed code from:
mcollapsingtoolbar = ... mcollapsingtoolbar.settitle(title);
to:
mtitlebar = ... setsupportactionbar(mtitlebar); getsupportactionbar().settitle(title);
but title not visible. device nexus 6 5.1.0
thanks in advance.
update 1: have changed code this, still not work :(
setsupportactionbar(mtoolbar); getsupportactionbar().settitle(title); getsupportactionbar().setdisplayshowtitleenabled(true); getsupportactionbar().sethomebuttonenabled(true); getsupportactionbar().setdisplayhomeasupenabled(true);
update 2: here code snippet 3 views:
private void setupappbarlayout() { appbarlayout appbarlayout = (appbarlayout) findviewbyid(r.id.appbar_layout); appbarlayout.setbackgroundcolor(extractbackgroundcolor()); } private void setupcollapsingtoolbarlayout() { if (null == mcollapsingtoolbar) { mcollapsingtoolbar = (collapsingtoolbarlayout) findviewbyid(r.id.collapsing_toolbar); } } private void setuptoolbar(string title) { mtoolbar = (toolbar) findviewbyid(r.id.tb_main); mtoolbar.setnavigationonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { supportfinishaftertransition(); } }); mtoolbar.inflatemenu(r.menu.menu_group_activity); mtoolbar.setonmenuitemclicklistener(new toolbar.onmenuitemclicklistener() { @override public boolean onmenuitemclick(menuitem item) { if (r.id.action_settings == item.getitemid()) { ... return true; } else { return false; } } }); mtoolbar.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mrecyclerview.smoothscrolltoposition(0); } }); setsupportactionbar(mtoolbar); getsupportactionbar().settitle(title); getsupportactionbar().setdisplayshowtitleenabled(true); getsupportactionbar().sethomebuttonenabled(true); getsupportactionbar().setdisplayhomeasupenabled(true); }
after called setsupportactionbar(mtoolbar), both title , menu invisible.
it looks title toolbar gone when wrap inside collapsingtoolbarlayout, solution got issue create new textview , add toolbar, remember toolbar viewgroup, can add widgets it. it's not clean like, works now.
textview text = new textview(this); text.settext(title); text.settextappearance(this, android.r.style.textappearance_material_widget_actionbar_title_inverse); toolbar.addview(text);
hope can find xml-friendly solution soon, too.
Comments
Post a Comment