Toolbar menu 遇到的问题

1、改变更多icon的颜色为白色:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  4.     android:id="@+id/toobar"  
  5.     android:layout_width="match_parent"  
  6.     android:layout_height="?attr/actionBarSize"  
  7.     android:background="?attr/colorPrimary"  
  8.     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"  
  9.     app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>  

设置theme为这个即可。

2、toolbar 设置返回箭头:

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. getSupportActionBar().setDisplayHomeAsUpEnabled(true);  

3、toolbar 返回箭头监听:

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. toolbar.setNavigationOnClickListener(new View.OnClickListener() {  
  2.            @Override  
  3.            public void onClick(View v) {  
  4.                finish();  
  5.            }  
  6.        });  


设置menu的位置:

style.xml

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <style name="OverflowMenuStyle" parent="@style/Widget.AppCompat.PopupMenu.Overflow">  
  2.         <!-- 是否覆盖锚点,默认为true,即盖住Toolbar -->  
  3.         <item name="overlapAnchor">false</item>  
  4.         <item name="android:dropDownWidth">wrap_content</item>  
  5.         <item name="android:paddingRight">5dp</item>  
  6.         <!-- 弹出层背景颜色 -->  
  7.         <item name="android:popupBackground">@android:color/white</item>  
  8.         <!-- 弹出层垂直方向上的偏移,即在竖直方向上距离Toolbar的距离,值为负则会盖住Toolbar -->  
  9.         <item name="android:dropDownVerticalOffset">5dp</item>  
  10.         <!-- 弹出层水平方向上的偏移,即距离屏幕左边的距离,负值会导致右边出现空隙 -->  
  11.         <item name="android:dropDownHorizontalOffset">0dp</item>  
  12.         <!-- 设置弹出菜单文字颜色 -->  
  13.         <item name="android:textColor">@android:color/black</item>  
  14.         <item name="android:gradientRadius">15dp</item>  
  15.         <item name="android:radius">50dp</item>  
  16.   
  17.     </style>  
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <!-- Base application theme. -->  
  2.    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">  
  3.        <!-- Customize your theme here. -->  
  4.        <item name="colorPrimary">@color/colorPrimary</item>  
  5.        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>  
  6.        <item name="colorAccent">@color/colorAccent</item>  
  7.        <!-- 加入toolbar溢出【弹出】菜单的风格 -->  
  8.        <item name="actionOverflowMenuStyle">@style/OverflowMenuStyle</item>  
  9.    </style>  
toolbar:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <android.support.v7.widget.Toolbar  
  2.         android:id="@+id/toolbar"  
  3.         android:minHeight="?attr/actionBarSize"  
  4.         android:layout_width="match_parent"  
  5.         android:layout_height="wrap_content"  
  6.         app:titleTextColor="@android:color/white"  
  7.         android:background="?attr/colorPrimary"  
  8.         android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"  
  9.         app:popupTheme="@style/OverflowMenuStyle">  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值