• 目录视图
  • 摘要视图
  • 订阅

Android ToolBar使用

标签:androidToolbar 3343人阅读 评论(0) 举报 分类: Android心得笔记(4)

目录(?)[+]

Android Toolbar:

ToolBar是Android 5.0(API Level 21)之后用来取代ActionBar的

ToolBar的优势:

Toolbar本身是一个 ViewGroup(而Actionbar直接继承自object)相比Actionbar可以更加灵活的配置使用。

引入方式:

在布局文件中引入support V7包下的ToolBar控件:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">android</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">support</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">v7</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">widget</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Toolbar</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">id</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@+id/toolbar"</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">layout_width</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"match_parent"</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">layout_height</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"wrap_content"</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">background</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@color/blue"</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">theme</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@style/Theme.ToolBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">android</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">support</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">v7</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">widget</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
在代码中像使用其他控件一样拿到ToolBar的引用:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Toolbar</span><span class="pln" style="color: rgb(72, 72, 76);"> toolbar </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> findViewById</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">id</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div></div>
设置右上角的menu菜单:调用Toolbar的inflateMenu()方法,传入一个Menu的xml文件
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">inflateMenu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div></div>
或者覆盖onCreateOptionsMenu()方法
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onCreateOptionsMenu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Menu</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="com" style="color: rgb(147, 161, 161);">// Inflate the menu; this adds items to the action bar if it is present.</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        getMenuInflater</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">inflate</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">main</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

ToolBar的配置:

代码方式: 配置主标题:标题内容和颜色
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setTitle</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"Title"</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="com" style="color: rgb(147, 161, 161);">//设置主标题</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setTitleTextColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">getResources</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">getColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">android</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">color</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">white</span><span class="pun" style="color: rgb(147, 161, 161);">));</span><span class="com" style="color: rgb(147, 161, 161);">//设置主标题颜色</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setTitleTextAppearance</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">this</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Theme_ToolBar_Base_Title</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="com" style="color: rgb(147, 161, 161);">//修改主标题的外观,包括文字颜色,文字大小等</span></code></div></div>
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.ToolBar.Base.Title"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@style/TextAppearance.Widget.AppCompat.Toolbar.Title"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textSize"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">20sp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColor"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">color_red</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置副标题:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setSubtitle</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"Subtitle"</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="com" style="color: rgb(147, 161, 161);">//设置子标题</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setSubtitleTextColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">getResources</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">getColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">android</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">color</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">darker_gray</span><span class="pun" style="color: rgb(147, 161, 161);">));</span><span class="com" style="color: rgb(147, 161, 161);">//设置子标题颜色</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setSubtitleTextAppearance</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">this</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Theme_ToolBar_Base_Subtitle</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="com" style="color: rgb(147, 161, 161);">//设置子标题的外观,包括文字颜色,文字大小等</span></code></div></div>
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.ToolBar.Base.Subtitle"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textSize"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">15sp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColor"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">color_43d28d</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置Home导航图标
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setNavigationIcon</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">mipmap</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">home</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div></div>
配置Logo:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setLogo</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">mipmap</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">ic_logo</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div></div>
配置ToolBar背景色: 方式一:布局文件中设置android:background属性
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">background</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@color/blue"</span></code></div></div>
方式二:代码中调用toolbar的 setBackgroundColor()方法
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setBackgroundColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">getResources</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">getColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">color</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">color_red</span><span class="pun" style="color: rgb(147, 161, 161);">));</span></code></div></div>
响应Menu菜单的点击事件:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setOnMenuItemClickListener</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">new</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">OnMenuItemClickListener</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onMenuItemClick</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">MenuItem</span><span class="pln" style="color: rgb(72, 72, 76);"> item</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> menuItemId </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> item</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getItemId</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">menuItemId </span><span class="pun" style="color: rgb(147, 161, 161);">==</span><span class="pln" style="color: rgb(72, 72, 76);"> R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">id</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">action_search</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="com" style="color: rgb(147, 161, 161);">//do something</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="pun" style="color: rgb(147, 161, 161);">}</span><span class="pln" style="color: rgb(72, 72, 76);"> </span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">});</span></code></div></div>
或者覆盖 onOptionsItemSelected()方法
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onOptionsItemSelected</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">MenuItem</span><span class="pln" style="color: rgb(72, 72, 76);"> item</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="com" style="color: rgb(147, 161, 161);">// Handle action bar item clicks here. The action bar will</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="com" style="color: rgb(147, 161, 161);">// automatically handle clicks on the Home/Up button, so long</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="com" style="color: rgb(147, 161, 161);">// as you specify a parent activity in AndroidManifest.xml.</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> id </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> item</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getItemId</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="com" style="color: rgb(147, 161, 161);">//noinspection SimplifiableIfStatement</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">id </span><span class="pun" style="color: rgb(147, 161, 161);">==</span><span class="pln" style="color: rgb(72, 72, 76);"> R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">id</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">action_search</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">super</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">onOptionsItemSelected</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

防止没有Menu按键的手机不显示Menu:

该特性由ViewConfiguration这个类中一个叫做sHasPermanentMenuKey的静态变量控制,系统根据这个变量的值来判断手机有没有物理Menu键的。当然这是一个内部变量,无法直接访问它,可以通过反射的方式修改它的值,让它为false。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">private</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> setMenuAlwaysShow</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">try</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="typ" style="color: teal;">ViewConfiguration</span><span class="pln" style="color: rgb(72, 72, 76);"> config </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">ViewConfiguration</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">get</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">this</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="typ" style="color: teal;">Field</span><span class="pln" style="color: rgb(72, 72, 76);"> menuKeyField </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">ViewConfiguration</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="kwd" style="color: rgb(30, 52, 123);">class</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getDeclaredField</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"sHasPermanentMenuKey"</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            menuKeyField</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setAccessible</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            menuKeyField</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setBoolean</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">config</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">false</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">catch</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Exception</span><span class="pln" style="color: rgb(72, 72, 76);"> e</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            e</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">printStackTrace</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

此处参考: Android ActionBar完全解析,使用官方推荐的最佳导航栏(上) - 郭霖的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/guolin_blog/article/details/18234477

配置Menu的icon图标:

在ToolBar的主题中配置name="actionOverflowButtonStyle"属性,创建一个主题继承自android:style/Widget.Holo.Light.ActionButton.Overflow,配置name="android:src"属性:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.ToolBar.Base"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.AppCompat.Light.NoActionBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textSize"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">20sp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColorPrimary"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">black_424242</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);">s</span><span class="pun" style="color: rgb(147, 161, 161);">设置</span><span class="typ" style="color: teal;">Menu</span><span class="pun" style="color: rgb(147, 161, 161);">菜单的背景色--></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:itemBackground"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">blue_600</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--设置</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">菜单不遮挡</span><span class="pln" style="color: rgb(72, 72, 76);">actionbar</span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"actionOverflowMenuStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">OverflowMenu</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--配置</span><span class="typ" style="color: teal;">Menu</span><span class="pun" style="color: rgb(147, 161, 161);">的图标--></span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"actionOverflowButtonStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">ToolBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">ActionButton</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Overflow</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"ToolBar.ActionButton.Overflow"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:style/Widget.Holo.Light.ActionButton.Overflow"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:src"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@mipmap</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">ic_menu_more_overflow</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置Menu菜单的OvweFlow的action

基本和ActionBar相同

配置OvweFlow中的action文字颜色:

在ToolBar的主题中配置android:textColorPrimary属性
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.ToolBar.Base"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.AppCompat.Light.NoActionBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textSize"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">20sp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColorPrimary"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">color_red</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
或者在Toolbar的 app:popupTheme="@style/AppTheme.PopupOverlay"主题中配置android:textColorPrimary属性:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> app</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">popupTheme</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@style/AppTheme.PopupOverlay"</span></code></div></div>
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"AppTheme.PopupOverlay"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"ThemeOverlay.AppCompat.Light"</span><span class="pun" style="color: rgb(147, 161, 161);">>></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColorPrimary"</span><span class="pun" style="color: rgb(147, 161, 161);">>#</span><span class="pln" style="color: rgb(72, 72, 76);">fff</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置OvweFlow中的action背景:

ToolBar的主题中配置android:itemBackground 属性
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);">s</span><span class="pun" style="color: rgb(147, 161, 161);">设置</span><span class="typ" style="color: teal;">Menu</span><span class="pun" style="color: rgb(147, 161, 161);">菜单的背景色--></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:itemBackground"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">black_light</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置OvweFlow中的action的宽度:

在Toolbar的popupTheme中设置android:width属性,但是注意Item的宽度有最大最小的限制,超过该限制后显示效果是最大宽度和最小宽度。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"AppTheme.PopupOverlay"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"ThemeOverlay.AppCompat.Light"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="typ" style="color: teal;">Item</span><span class="pun" style="color: rgb(147, 161, 161);">的宽度--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:width"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">400dp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColorPrimary"</span><span class="pun" style="color: rgb(147, 161, 161);">>#</span><span class="pln" style="color: rgb(72, 72, 76);">fff</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置OvweFlow中的action显示icon:

默认情况下OverFlow中只显示文字,但这样不够美观。 在Toolbar的popupTheme中设置android:drawableRight android:drawableLeft android:drawableTop android:drawableBottom属性,注意这个设置对所有Item统一生效的,这样也就没有太大的意义。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><!--<</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:drawableLeft"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@drawable</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">ic_action_search</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">>--></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:drawableRight"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@drawable</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">ic_home_gray_36dp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:drawableTop"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@drawable</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">ic_textsms_gray_36dp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
是否显示Icon是由MenuBuilder这个类的setOptionalIconsVisible方法来决定的,该方法不能直接调用,可以反射之。重写boolean onCreatePanelMenu(int featureId, Menu menu)方法,在menu创建的时候调用之。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onCreatePanelMenu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> featureId</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Menu</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">menu </span><span class="pun" style="color: rgb(147, 161, 161);">!=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">null</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getClass</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">getSimpleName</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">equals</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"MenuBuilder"</span><span class="pun" style="color: rgb(147, 161, 161);">))</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">try</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="typ" style="color: teal;">Method</span><span class="pln" style="color: rgb(72, 72, 76);"> m </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getClass</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">getDeclaredMethod</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"setOptionalIconsVisible"</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Boolean</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">TYPE</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    m</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setAccessible</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    m</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">invoke</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="pun" style="color: rgb(147, 161, 161);">}</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">catch</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Exception</span><span class="pln" style="color: rgb(72, 72, 76);"> e</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    e</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">printStackTrace</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">super</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">onCreatePanelMenu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">featureId</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

配置OvweFlow中的action间的分割线:

在Toolbar的popupTheme中设置android:dividerHeight属性,设置高度大于0就能显示分割线,分割线的默认颜色是白色。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:dividerHeight"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">1dp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置ToolBar的Menu不遮挡ToolBar:

Actionbar中的配置方式是:设置actionOverflowMenuStyle的android:overlapAnchor属性为false.这里同样,不过注意是在ToolBar的主题中而不是Activity的主题。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.ToolBar.Base"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.AppCompat.Light.NoActionBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textSize"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">20sp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColorPrimary"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">color_red</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);">s</span><span class="pun" style="color: rgb(147, 161, 161);">设置</span><span class="typ" style="color: teal;">Menu</span><span class="pun" style="color: rgb(147, 161, 161);">菜单的背景色--></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:itemBackground"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">gray</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--设置</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">菜单不遮挡</span><span class="pln" style="color: rgb(72, 72, 76);">actionbar</span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"actionOverflowMenuStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">OverflowMenu</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"OverflowMenu"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Widget.AppCompat.PopupMenu.Overflow"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--兼容</span><span class="typ" style="color: teal;">Api</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">21</span><span class="pun" style="color: rgb(147, 161, 161);">之前的版本</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"overlapAnchor"</span><span class="pun" style="color: rgb(147, 161, 161);">>false</span><span class="kwd" style="color: rgb(30, 52, 123);"></span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Api</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">21</span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:overlapAnchor"</span><span class="pun" style="color: rgb(147, 161, 161);">>false</span><span class="kwd" style="color: rgb(30, 52, 123);"></span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置ToolBar的Home图标左侧间隙

在布局中Toolbar控件中配置属性 app:contentInsetStart="3dp"
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> app</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">contentInsetStart</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"3dp"</span></code></div></div>

ToolBar的状态栏沉浸效果:

配置ToolBar和系统状态栏背景色一致:必须配置不使用半透明状态栏才可以设置状态栏颜色,需要 android4.4( Api Level 19)及以上
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.MyActivity"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.AppCompat.Light.NoActionBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Customize</span><span class="pln" style="color: rgb(72, 72, 76);"> your theme here</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--配置是否使用半透明状态栏--></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowTranslucentStatus"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">false</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowTranslucentNavigation"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--状态栏颜色--></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:statusBarColor"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">color_0176da</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

设置Toolbar 浮动:

ToolBar 没有提供显示和隐藏的方法,首先调用 setSupportActionBar(toolbar);方法把ToolBar设置为ActionBar,再使用ActionBar的方式显示隐藏 点击屏幕后显示隐藏ToolBar;
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onTouchEvent</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">MotionEvent</span><span class="pln" style="color: rgb(72, 72, 76);"> event</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">==</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">null</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> getSupportActionBar</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">switch</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">event</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getAction</span><span class="pun" style="color: rgb(147, 161, 161);">())</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">case</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">MotionEvent</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">ACTION_UP</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">!=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">null</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">isShowing</span><span class="pun" style="color: rgb(147, 161, 161);">())</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">hide</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">else</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">show</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">break</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">super</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">onTouchEvent</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">event</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>
但是这样设置 setSupportActionBar(toolbar);之后,如果是直接在ToolBar上设置的Menu的方式; toolbar.inflateMenu(R.menu.base_toolbar_menu); ToolBar上的Menu菜单会消失,这时候需要使用复写方式添加Menu
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onCreateOptionsMenu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Menu</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        getMenuInflater</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">inflate</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">base_toolbar_menu</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>
ToolBar和一个普通控件是一样的,所以浮动效果应该通过布局搞定,设置Toolbar 的根布局为相对布局,同时添加一个移动动画 设置Activity的主题:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"ToolbarActivityTheme"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"AppTheme"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--启用</span><span class="typ" style="color: teal;">ActionBar</span><span class="pun" style="color: rgb(147, 161, 161);">的叠加模式(不生效)--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"windowActionBarOverlay"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--状态栏半透明--></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowTranslucentStatus"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--内容填充到导航栏--></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowTranslucentNavigation"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--设置全屏--></span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowFullscreen"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
添加动画和隐藏效果:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onTouchEvent</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">MotionEvent</span><span class="pln" style="color: rgb(72, 72, 76);"> event</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">==</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">null</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> getSupportActionBar</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">switch</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">event</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getAction</span><span class="pun" style="color: rgb(147, 161, 161);">())</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">case</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">MotionEvent</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">ACTION_UP</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">!=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">null</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">isShowing</span><span class="pun" style="color: rgb(147, 161, 161);">())</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> height </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getMeasuredHeight</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        height </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> height </span><span class="pun" style="color: rgb(147, 161, 161);"><=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">?</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">112</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);"> height</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        startAnimation</span><span class="pun" style="color: rgb(147, 161, 161);">(-</span><span class="pln" style="color: rgb(72, 72, 76);">height</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">new</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Runnable</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> run</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                                actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">hide</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        </span><span class="pun" style="color: rgb(147, 161, 161);">});</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">else</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">show</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        startAnimation</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">new</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Runnable</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> run</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        </span><span class="pun" style="color: rgb(147, 161, 161);">});</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">break</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">super</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">onTouchEvent</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">event</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="lit" style="color: rgb(25, 95, 145);">@TargetApi</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Build</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">VERSION_CODES</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">ICE_CREAM_SANDWICH</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">private</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> startAnimation</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> transY</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">final</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Runnable</span><span class="pln" style="color: rgb(72, 72, 76);"> end</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="typ" style="color: teal;">ViewPropertyAnimator</span><span class="pln" style="color: rgb(72, 72, 76);"> animator </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">animate</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">translationY</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">transY</span><span class="pun" style="color: rgb(147, 161, 161);">).</span><span class="pln" style="color: rgb(72, 72, 76);">setDuration</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">600</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        animator</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">start</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        animator</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setListener</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">new</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Animator</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">AnimatorListener</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> onAnimationStart</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Animator</span><span class="pln" style="color: rgb(72, 72, 76);"> animation</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> onAnimationEnd</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Animator</span><span class="pln" style="color: rgb(72, 72, 76);"> animation</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                end</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">run</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> onAnimationCancel</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Animator</span><span class="pln" style="color: rgb(72, 72, 76);"> animation</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> onAnimationRepeat</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Animator</span><span class="pln" style="color: rgb(72, 72, 76);"> animation</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">});</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

配置Activity内容填充到系统状态栏:

这样Activity的整个内容会冲到屏幕顶部,不是导航栏透明
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowTranslucentNavigation"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

ToolBar的navigationIcon一直居上不居中的异常:



排查原因竟然是在Activity中设置ToolBar的主题......哪怕这个主题中什么都不写,这个图标依然会居上,不明白什么原因
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"ToolBarActivityTheme"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.AppCompat.Light"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--使用</span><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">取消默认的</span><span class="pln" style="color: rgb(72, 72, 76);">actionbar</span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowActionBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">false</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"windowNoTitle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:actionBarStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">TranslucentActionBar</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--设置</span><span class="typ" style="color: teal;">ActionBar</span><span class="pun" style="color: rgb(147, 161, 161);">的主题--></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--<</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:toolbarStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">ToolBarActivityToolbarTheme</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">>--></span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"toolbarStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">ToolBarActivityToolbarTheme</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
修改后效果:

  • 目录视图
  • 摘要视图
  • 订阅

Android ToolBar使用

标签:androidToolbar 3343人阅读 评论(0) 举报 分类: Android心得笔记(4)

目录(?)[+]

Android Toolbar:

ToolBar是Android 5.0(API Level 21)之后用来取代ActionBar的

ToolBar的优势:

Toolbar本身是一个 ViewGroup(而Actionbar直接继承自object)相比Actionbar可以更加灵活的配置使用。

引入方式:

在布局文件中引入support V7包下的ToolBar控件:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">android</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">support</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">v7</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">widget</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Toolbar</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">id</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@+id/toolbar"</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">layout_width</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"match_parent"</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">layout_height</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"wrap_content"</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">background</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@color/blue"</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">theme</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@style/Theme.ToolBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">android</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">support</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">v7</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">widget</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
在代码中像使用其他控件一样拿到ToolBar的引用:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Toolbar</span><span class="pln" style="color: rgb(72, 72, 76);"> toolbar </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> findViewById</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">id</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div></div>
设置右上角的menu菜单:调用Toolbar的inflateMenu()方法,传入一个Menu的xml文件
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">inflateMenu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div></div>
或者覆盖onCreateOptionsMenu()方法
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onCreateOptionsMenu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Menu</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="com" style="color: rgb(147, 161, 161);">// Inflate the menu; this adds items to the action bar if it is present.</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        getMenuInflater</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">inflate</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">main</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

ToolBar的配置:

代码方式: 配置主标题:标题内容和颜色
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setTitle</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"Title"</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="com" style="color: rgb(147, 161, 161);">//设置主标题</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setTitleTextColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">getResources</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">getColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">android</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">color</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">white</span><span class="pun" style="color: rgb(147, 161, 161);">));</span><span class="com" style="color: rgb(147, 161, 161);">//设置主标题颜色</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setTitleTextAppearance</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">this</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Theme_ToolBar_Base_Title</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="com" style="color: rgb(147, 161, 161);">//修改主标题的外观,包括文字颜色,文字大小等</span></code></div></div>
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.ToolBar.Base.Title"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@style/TextAppearance.Widget.AppCompat.Toolbar.Title"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textSize"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">20sp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColor"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">color_red</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置副标题:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setSubtitle</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"Subtitle"</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="com" style="color: rgb(147, 161, 161);">//设置子标题</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setSubtitleTextColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">getResources</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">getColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">android</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">color</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">darker_gray</span><span class="pun" style="color: rgb(147, 161, 161);">));</span><span class="com" style="color: rgb(147, 161, 161);">//设置子标题颜色</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setSubtitleTextAppearance</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">this</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Theme_ToolBar_Base_Subtitle</span><span class="pun" style="color: rgb(147, 161, 161);">);</span><span class="com" style="color: rgb(147, 161, 161);">//设置子标题的外观,包括文字颜色,文字大小等</span></code></div></div>
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.ToolBar.Base.Subtitle"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textSize"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">15sp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColor"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">color_43d28d</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置Home导航图标
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setNavigationIcon</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">mipmap</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">home</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div></div>
配置Logo:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setLogo</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">mipmap</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">ic_logo</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div></div>
配置ToolBar背景色: 方式一:布局文件中设置android:background属性
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">android</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">background</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@color/blue"</span></code></div></div>
方式二:代码中调用toolbar的 setBackgroundColor()方法
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setBackgroundColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">getResources</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">getColor</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">color</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">color_red</span><span class="pun" style="color: rgb(147, 161, 161);">));</span></code></div></div>
响应Menu菜单的点击事件:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setOnMenuItemClickListener</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">new</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">OnMenuItemClickListener</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onMenuItemClick</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">MenuItem</span><span class="pln" style="color: rgb(72, 72, 76);"> item</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> menuItemId </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> item</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getItemId</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">menuItemId </span><span class="pun" style="color: rgb(147, 161, 161);">==</span><span class="pln" style="color: rgb(72, 72, 76);"> R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">id</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">action_search</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="com" style="color: rgb(147, 161, 161);">//do something</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="pun" style="color: rgb(147, 161, 161);">}</span><span class="pln" style="color: rgb(72, 72, 76);"> </span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">});</span></code></div></div>
或者覆盖 onOptionsItemSelected()方法
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onOptionsItemSelected</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">MenuItem</span><span class="pln" style="color: rgb(72, 72, 76);"> item</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="com" style="color: rgb(147, 161, 161);">// Handle action bar item clicks here. The action bar will</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="com" style="color: rgb(147, 161, 161);">// automatically handle clicks on the Home/Up button, so long</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="com" style="color: rgb(147, 161, 161);">// as you specify a parent activity in AndroidManifest.xml.</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> id </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> item</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getItemId</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="com" style="color: rgb(147, 161, 161);">//noinspection SimplifiableIfStatement</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">id </span><span class="pun" style="color: rgb(147, 161, 161);">==</span><span class="pln" style="color: rgb(72, 72, 76);"> R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">id</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">action_search</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">super</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">onOptionsItemSelected</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

防止没有Menu按键的手机不显示Menu:

该特性由ViewConfiguration这个类中一个叫做sHasPermanentMenuKey的静态变量控制,系统根据这个变量的值来判断手机有没有物理Menu键的。当然这是一个内部变量,无法直接访问它,可以通过反射的方式修改它的值,让它为false。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">private</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> setMenuAlwaysShow</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">try</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="typ" style="color: teal;">ViewConfiguration</span><span class="pln" style="color: rgb(72, 72, 76);"> config </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">ViewConfiguration</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">get</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">this</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="typ" style="color: teal;">Field</span><span class="pln" style="color: rgb(72, 72, 76);"> menuKeyField </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">ViewConfiguration</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="kwd" style="color: rgb(30, 52, 123);">class</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getDeclaredField</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"sHasPermanentMenuKey"</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            menuKeyField</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setAccessible</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            menuKeyField</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setBoolean</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">config</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">false</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">catch</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Exception</span><span class="pln" style="color: rgb(72, 72, 76);"> e</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            e</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">printStackTrace</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

此处参考: Android ActionBar完全解析,使用官方推荐的最佳导航栏(上) - 郭霖的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/guolin_blog/article/details/18234477

配置Menu的icon图标:

在ToolBar的主题中配置name="actionOverflowButtonStyle"属性,创建一个主题继承自android:style/Widget.Holo.Light.ActionButton.Overflow,配置name="android:src"属性:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.ToolBar.Base"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.AppCompat.Light.NoActionBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textSize"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">20sp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColorPrimary"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">black_424242</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);">s</span><span class="pun" style="color: rgb(147, 161, 161);">设置</span><span class="typ" style="color: teal;">Menu</span><span class="pun" style="color: rgb(147, 161, 161);">菜单的背景色--></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:itemBackground"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">blue_600</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--设置</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">菜单不遮挡</span><span class="pln" style="color: rgb(72, 72, 76);">actionbar</span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"actionOverflowMenuStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">OverflowMenu</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--配置</span><span class="typ" style="color: teal;">Menu</span><span class="pun" style="color: rgb(147, 161, 161);">的图标--></span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"actionOverflowButtonStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">ToolBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">ActionButton</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Overflow</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"ToolBar.ActionButton.Overflow"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:style/Widget.Holo.Light.ActionButton.Overflow"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:src"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@mipmap</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">ic_menu_more_overflow</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置Menu菜单的OvweFlow的action

基本和ActionBar相同

配置OvweFlow中的action文字颜色:

在ToolBar的主题中配置android:textColorPrimary属性
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.ToolBar.Base"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.AppCompat.Light.NoActionBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textSize"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">20sp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColorPrimary"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">color_red</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
或者在Toolbar的 app:popupTheme="@style/AppTheme.PopupOverlay"主题中配置android:textColorPrimary属性:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> app</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">popupTheme</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"@style/AppTheme.PopupOverlay"</span></code></div></div>
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"AppTheme.PopupOverlay"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"ThemeOverlay.AppCompat.Light"</span><span class="pun" style="color: rgb(147, 161, 161);">>></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColorPrimary"</span><span class="pun" style="color: rgb(147, 161, 161);">>#</span><span class="pln" style="color: rgb(72, 72, 76);">fff</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置OvweFlow中的action背景:

ToolBar的主题中配置android:itemBackground 属性
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);">s</span><span class="pun" style="color: rgb(147, 161, 161);">设置</span><span class="typ" style="color: teal;">Menu</span><span class="pun" style="color: rgb(147, 161, 161);">菜单的背景色--></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:itemBackground"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">black_light</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置OvweFlow中的action的宽度:

在Toolbar的popupTheme中设置android:width属性,但是注意Item的宽度有最大最小的限制,超过该限制后显示效果是最大宽度和最小宽度。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"AppTheme.PopupOverlay"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"ThemeOverlay.AppCompat.Light"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="typ" style="color: teal;">Item</span><span class="pun" style="color: rgb(147, 161, 161);">的宽度--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:width"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">400dp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColorPrimary"</span><span class="pun" style="color: rgb(147, 161, 161);">>#</span><span class="pln" style="color: rgb(72, 72, 76);">fff</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置OvweFlow中的action显示icon:

默认情况下OverFlow中只显示文字,但这样不够美观。 在Toolbar的popupTheme中设置android:drawableRight android:drawableLeft android:drawableTop android:drawableBottom属性,注意这个设置对所有Item统一生效的,这样也就没有太大的意义。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><!--<</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:drawableLeft"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@drawable</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">ic_action_search</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">>--></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:drawableRight"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@drawable</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">ic_home_gray_36dp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:drawableTop"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@drawable</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">ic_textsms_gray_36dp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
是否显示Icon是由MenuBuilder这个类的setOptionalIconsVisible方法来决定的,该方法不能直接调用,可以反射之。重写boolean onCreatePanelMenu(int featureId, Menu menu)方法,在menu创建的时候调用之。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onCreatePanelMenu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> featureId</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Menu</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">menu </span><span class="pun" style="color: rgb(147, 161, 161);">!=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">null</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getClass</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">getSimpleName</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">equals</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"MenuBuilder"</span><span class="pun" style="color: rgb(147, 161, 161);">))</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">try</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="typ" style="color: teal;">Method</span><span class="pln" style="color: rgb(72, 72, 76);"> m </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getClass</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">getDeclaredMethod</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="str" style="color: rgb(221, 17, 68);">"setOptionalIconsVisible"</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Boolean</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">TYPE</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    m</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setAccessible</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    m</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">invoke</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="pun" style="color: rgb(147, 161, 161);">}</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">catch</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Exception</span><span class="pln" style="color: rgb(72, 72, 76);"> e</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    e</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">printStackTrace</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">super</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">onCreatePanelMenu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">featureId</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

配置OvweFlow中的action间的分割线:

在Toolbar的popupTheme中设置android:dividerHeight属性,设置高度大于0就能显示分割线,分割线的默认颜色是白色。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:dividerHeight"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">1dp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置ToolBar的Menu不遮挡ToolBar:

Actionbar中的配置方式是:设置actionOverflowMenuStyle的android:overlapAnchor属性为false.这里同样,不过注意是在ToolBar的主题中而不是Activity的主题。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.ToolBar.Base"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.AppCompat.Light.NoActionBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textSize"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">20sp</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:textColorPrimary"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">color_red</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);">s</span><span class="pun" style="color: rgb(147, 161, 161);">设置</span><span class="typ" style="color: teal;">Menu</span><span class="pun" style="color: rgb(147, 161, 161);">菜单的背景色--></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:itemBackground"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">gray</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--设置</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">菜单不遮挡</span><span class="pln" style="color: rgb(72, 72, 76);">actionbar</span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"actionOverflowMenuStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">OverflowMenu</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"OverflowMenu"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Widget.AppCompat.PopupMenu.Overflow"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--兼容</span><span class="typ" style="color: teal;">Api</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">21</span><span class="pun" style="color: rgb(147, 161, 161);">之前的版本</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"overlapAnchor"</span><span class="pun" style="color: rgb(147, 161, 161);">>false</span><span class="kwd" style="color: rgb(30, 52, 123);"></span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Api</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">21</span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:overlapAnchor"</span><span class="pun" style="color: rgb(147, 161, 161);">>false</span><span class="kwd" style="color: rgb(30, 52, 123);"></span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

配置ToolBar的Home图标左侧间隙

在布局中Toolbar控件中配置属性 app:contentInsetStart="3dp"
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> app</span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);">contentInsetStart</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"3dp"</span></code></div></div>

ToolBar的状态栏沉浸效果:

配置ToolBar和系统状态栏背景色一致:必须配置不使用半透明状态栏才可以设置状态栏颜色,需要 android4.4( Api Level 19)及以上
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">  </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.MyActivity"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.AppCompat.Light.NoActionBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Customize</span><span class="pln" style="color: rgb(72, 72, 76);"> your theme here</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--配置是否使用半透明状态栏--></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowTranslucentStatus"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">false</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowTranslucentNavigation"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--状态栏颜色--></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:statusBarColor"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@color</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">color_0176da</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

设置Toolbar 浮动:

ToolBar 没有提供显示和隐藏的方法,首先调用 setSupportActionBar(toolbar);方法把ToolBar设置为ActionBar,再使用ActionBar的方式显示隐藏 点击屏幕后显示隐藏ToolBar;
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onTouchEvent</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">MotionEvent</span><span class="pln" style="color: rgb(72, 72, 76);"> event</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">==</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">null</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> getSupportActionBar</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">switch</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">event</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getAction</span><span class="pun" style="color: rgb(147, 161, 161);">())</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">case</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">MotionEvent</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">ACTION_UP</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">!=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">null</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">isShowing</span><span class="pun" style="color: rgb(147, 161, 161);">())</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">hide</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">else</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">show</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">break</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">super</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">onTouchEvent</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">event</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>
但是这样设置 setSupportActionBar(toolbar);之后,如果是直接在ToolBar上设置的Menu的方式; toolbar.inflateMenu(R.menu.base_toolbar_menu); ToolBar上的Menu菜单会消失,这时候需要使用复写方式添加Menu
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onCreateOptionsMenu</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Menu</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        getMenuInflater</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">inflate</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">R</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">menu</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">base_toolbar_menu</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> menu</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>
ToolBar和一个普通控件是一样的,所以浮动效果应该通过布局搞定,设置Toolbar 的根布局为相对布局,同时添加一个移动动画 设置Activity的主题:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"ToolbarActivityTheme"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"AppTheme"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--启用</span><span class="typ" style="color: teal;">ActionBar</span><span class="pun" style="color: rgb(147, 161, 161);">的叠加模式(不生效)--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"windowActionBarOverlay"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--状态栏半透明--></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowTranslucentStatus"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--内容填充到导航栏--></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowTranslucentNavigation"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--设置全屏--></span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowFullscreen"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
添加动画和隐藏效果:
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">boolean</span><span class="pln" style="color: rgb(72, 72, 76);"> onTouchEvent</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">MotionEvent</span><span class="pln" style="color: rgb(72, 72, 76);"> event</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">==</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">null</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> getSupportActionBar</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">switch</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">event</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getAction</span><span class="pun" style="color: rgb(147, 161, 161);">())</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">case</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">MotionEvent</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">ACTION_UP</span><span class="pun" style="color: rgb(147, 161, 161);">:</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar </span><span class="pun" style="color: rgb(147, 161, 161);">!=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">null</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="kwd" style="color: rgb(30, 52, 123);">if</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">isShowing</span><span class="pun" style="color: rgb(147, 161, 161);">())</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        </span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> height </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">getMeasuredHeight</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        height </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> height </span><span class="pun" style="color: rgb(147, 161, 161);"><=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">?</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="lit" style="color: rgb(25, 95, 145);">112</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">:</span><span class="pln" style="color: rgb(72, 72, 76);"> height</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        startAnimation</span><span class="pun" style="color: rgb(147, 161, 161);">(-</span><span class="pln" style="color: rgb(72, 72, 76);">height</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">new</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Runnable</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> run</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                                actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">hide</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        </span><span class="pun" style="color: rgb(147, 161, 161);">});</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">else</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        actionBar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">show</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        startAnimation</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">0</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">new</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Runnable</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> run</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                        </span><span class="pun" style="color: rgb(147, 161, 161);">});</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                </span><span class="kwd" style="color: rgb(30, 52, 123);">break</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="kwd" style="color: rgb(30, 52, 123);">return</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">super</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">onTouchEvent</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">event</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="lit" style="color: rgb(25, 95, 145);">@TargetApi</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Build</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">VERSION_CODES</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">ICE_CREAM_SANDWICH</span><span class="pun" style="color: rgb(147, 161, 161);">)</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="kwd" style="color: rgb(30, 52, 123);">private</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> startAnimation</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">int</span><span class="pln" style="color: rgb(72, 72, 76);"> transY</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">final</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Runnable</span><span class="pln" style="color: rgb(72, 72, 76);"> end</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="typ" style="color: teal;">ViewPropertyAnimator</span><span class="pln" style="color: rgb(72, 72, 76);"> animator </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">animate</span><span class="pun" style="color: rgb(147, 161, 161);">().</span><span class="pln" style="color: rgb(72, 72, 76);">translationY</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">transY</span><span class="pun" style="color: rgb(147, 161, 161);">).</span><span class="pln" style="color: rgb(72, 72, 76);">setDuration</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="lit" style="color: rgb(25, 95, 145);">600</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        animator</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">start</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        animator</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">setListener</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="kwd" style="color: rgb(30, 52, 123);">new</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Animator</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">AnimatorListener</span><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> onAnimationStart</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Animator</span><span class="pln" style="color: rgb(72, 72, 76);"> animation</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> onAnimationEnd</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Animator</span><span class="pln" style="color: rgb(72, 72, 76);"> animation</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">                end</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">run</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> onAnimationCancel</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Animator</span><span class="pln" style="color: rgb(72, 72, 76);"> animation</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="lit" style="color: rgb(25, 95, 145);">@Override</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> onAnimationRepeat</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">Animator</span><span class="pln" style="color: rgb(72, 72, 76);"> animation</span><span class="pun" style="color: rgb(147, 161, 161);">)</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);">});</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

配置Activity内容填充到系统状态栏:

这样Activity的整个内容会冲到屏幕顶部,不是导航栏透明
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowTranslucentNavigation"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

ToolBar的navigationIcon一直居上不居中的异常:



排查原因竟然是在Activity中设置ToolBar的主题......哪怕这个主题中什么都不写,这个图标依然会居上,不明白什么原因
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">style name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"ToolBarActivityTheme"</span><span class="pln" style="color: rgb(72, 72, 76);"> parent</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"Theme.AppCompat.Light"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--使用</span><span class="pln" style="color: rgb(72, 72, 76);">toolbar</span><span class="pun" style="color: rgb(147, 161, 161);">取消默认的</span><span class="pln" style="color: rgb(72, 72, 76);">actionbar</span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:windowActionBar"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">false</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"windowNoTitle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="kwd" style="color: rgb(30, 52, 123);">true</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:actionBarStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">TranslucentActionBar</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--设置</span><span class="typ" style="color: teal;">ActionBar</span><span class="pun" style="color: rgb(147, 161, 161);">的主题--></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><!--<</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"android:toolbarStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">ToolBarActivityToolbarTheme</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">>--></span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">item name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"toolbarStyle"</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="lit" style="color: rgb(25, 95, 145);">@style</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="typ" style="color: teal;">ToolBarActivityToolbarTheme</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">item</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">style</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
修改后效果:

更多相关文章

  1. android 设置Button或者ImageButton的背景透明 半透明 透明
  2. Android(安卓)FactoryTest 流程
  3. android listview的一些设置
  4. Android(安卓)Material Design 控件常用的属性
  5. Android自学笔记之Android常见命令操作及一些普通布局属性
  6. Android学习记录使用Gallery实现炫丽的拖动效果
  7. Android(安卓)EditText属性大全
  8. android中用Spannable在TextView中设置超链接、颜色、字体
  9. Android--(6)--详解ImageButton属性

随机推荐

  1. Linux 下数据库定时备份
  2. zabbix设置企业微信群内机器人报警
  3. zabbix-agent安装配置------------------
  4. zabbix server 内存溢出 @第一次遇到
  5. TCP/IP 三次握手 四次握手
  6. weadmin
  7. windows server 2016安装网卡驱动【引用
  8. Mysql windows 下载安装教程
  9. zabbix-server centos7 (实用
  10. CF卡磁盘结构损坏怎么办 ,磁盘结构损坏的