homeObview.setOnScrollChangeListener(new View.OnScrollChangeListener() { @Override public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { //scrollY > oldScrollY:向上滑动 //scrollY < oldScrollY:向下滑动 // scrollY:滚动过的距离。 toolbarHeight = reSearch.getBottom() * 1.5f; if (scrollY <= toolbarHeight) { float scale = (float) scrollY / toolbarHeight; float alpha = scale * 255; reSearch.setBackgroundColor(Color.argb((int) alpha, 255, 0, 0)); } else { reSearch.setBackgroundColor(Color.RED); } } });
Android 滑动头标题变色
最新推荐文章于 2021-05-26 23:57:43 发布