为什么要使用Toolbar?
因为actionbar只能虚浮于视图上方,当你想把一个控件悬浮在actionbar上方时,就没招了。(可以通过addview的方式悬浮,但是有焦点问题,其它的控件没法获取焦点)
怎么办?使用Toolbar。
toolbar的基础用法请自行搜索。本文只描述遇到的坑。
本文是基于sdk 21的,23的坑没有填。
1.当自己设置toolbar样式,title使用textview,怎么隐藏原有的title:
getSupportActionBar().setDisplayShowTitleEnabled(
false);
2.怎么给text设置title:
TextView title = (TextView) findViewById(R.id.
title);
title.setText(getTitle());
3.为什么Toolbar左边有16dp的间距,如何修改:
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
4.
可以像actionbar那样直接点title和navigation跳转么?
不可以,自己做linelayout去绑定点击事件。
5.menu icon 不显示的问题:
<
menu
xmlns:
android
=
"http://schemas.android.com/apk/res/android"
xmlns: app = "http://schemas.android.com/apk/res-auto"
xmlns: tools = "http://schemas.android.com/tools"
tools :context= "com.zte.homenas.weshare.movie_old.MovieMainActivity" >
< item
android :id= "@+id/m_imageEdit"
android :icon= "@drawable/ic_edit"
android :orderInCategory= "900"
app :showAsAction= "always"
android :title= "@string/edit"/>
xmlns: app = "http://schemas.android.com/apk/res-auto"
xmlns: tools = "http://schemas.android.com/tools"
tools :context= "com.zte.homenas.weshare.movie_old.MovieMainActivity" >
< item
android :id= "@+id/m_imageEdit"
android :icon= "@drawable/ic_edit"
android :orderInCategory= "900"
app :showAsAction= "always"
android :title= "@string/edit"/>
</menu>
http://stackoverflow.com/questions/26638089/appcompat-v7-toolbar-as-actionbar-not-showing-always-actions-from-menu-but-ap
6.使用toolbar 默认白色字体,search view的字体也变白色了。。。
链接:
http://stackoverflow.com/questions/27156680/change-textcolor-in-searchview-using-android-toolbar
原因:
TextView
android:id="@+id/search_badge"