奶霸000

导航

android toolbar

 http://www.jianshu.com/p/79604c3ddcae


/**
次主题是为了设置toolbar 右边的三个小点 改变其图标样式用的
*/
<style name="Theme.ToolBar.ZhiHu" parent="Theme.AppCompat.Light.NoActionBar">
<item name="actionOverflowButtonStyle">@style/ActionButton.Overflow.ZhiHu</item>
</style>

<style name="ActionButton.Overflow.ZhiHu" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">@mipmap/ic_launcher</item>
</style>

在layout中进行引用
<android.support.v7.widget.Toolbar
toolbar:popupTheme="@style/MyToolBarTheme"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.ToolBar.ZhiHu"
android:background="@android:color/holo_red_dark">

<!--自定义控件-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clock" />
</android.support.v7.widget.Toolbar>

其中的theme就是这个作用
  android:theme="@style/Theme.ToolBar.ZhiHu"




这个是设置了toolbar
<!--ToolBar 样式-->
<style name="MyToolBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- toolbar颜色 -->
<item name="colorPrimary">@android:color/holo_red_dark</item>
<!-- 状态栏的颜色 -->
<item name="colorPrimaryDark">@android:color/holo_green_dark</item>
<item name="colorAccent">@android:color/holo_orange_dark</item>

<!--toolbar 上面的标题的颜色-->
<item name="android:textColorPrimary">@android:color/holo_orange_light</item>

<!-- toolbar的主题-->
<item name="toolbarStyle">@style/ClubToolbar</item>

<item name="contentInsetStart">0dp</item>
<item name="contentInsetEnd">0dp</item>


<!---->


</style>

<style name="ClubToolbar" parent="Widget.AppCompat.Toolbar">
<!-- 设置该属性解决空白部分-->
<item name="contentInsetStart">16dp</item>
<item name="contentInsetEnd">16dp</item>
</style>

<style name="Theme.ToolBar.ZhiHu" parent="Theme.AppCompat.Light.NoActionBar">
<item name="actionOverflowButtonStyle">@style/ActionButton.Overflow.ZhiHu</item>
</style>

<style name="ActionButton.Overflow.ZhiHu" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">@mipmap/ic_launcher</item>
</style>






posted on 2016-09-18 16:48  奶霸000  阅读(294)  评论(0编辑  收藏  举报