美团外卖app,顶部导航栏返回按钮的颜色变化

今天更新了美团外卖的APP,偶然发现顶部导航栏的返回按钮,随着滑动时,颜色会从白色过渡到红色,请问这个是怎么实现的??

之前做过类似的,不过不是改变颜色,是改变了图片(因为按钮前后的样子不一样),也就是判断某个alpha值时更改图片,但也就会突然的变化效果。。

阅读 5.1k
2 个回答

试试下面代码,放在drawable中

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"

android:shape="rectangle">  
<gradient android:startColor="#509245" android:centerColor="#3e8532"  
    android:endColor="#509245" android:type="linear" android:angle="90"  
    android:centerX="0.5" android:centerY="0.5" />  
<padding android:left="7dp" android:top="7dp" android:right="7dp"  
    android:bottom="7dp" />  
<corners android:radius="4dp" />  

</shape>

为 UIImage 新增个方法 imageWithColor:alpha: ,然后动态生成图片做为 NavBar 的背景图

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题