lot*_*ops 0 android transition background-color
我有一个透明的黑色背景视图:#DD000000
我想要的是,在某些情况下,视图从#223333FF转换回第一种颜色.
//lastApp.setBackgroundColor(getResources().getColor(R.color.semitransparent));
ColorDrawable[] color = {new ColorDrawable(Color.BLUE), new ColorDrawable(Color.BLACK)};
TransitionDrawable trans = new TransitionDrawable(color);
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
lastApp.setBackgroundDrawable(trans);
} else {
lastApp.setBackground(trans);
}
trans.startTransition(300);
Run Code Online (Sandbox Code Playgroud)
这段代码有效,但颜色不是我想要的颜色.
如果我使用下一行,我相信它会创建两种黑色,因为我没有看到任何蓝色,并且透明度丢失了.
ColorDrawable[] color = {new ColorDrawable(getResources().getColor(R.color.blue)), new ColorDrawable(getResources().getColor(R.color.black_overlay))};
Run Code Online (Sandbox Code Playgroud)
我的下一次尝试是使用没有alpha的资源:#DD000000 - >#000000; #223333FF - >#3333FF这里的过渡有效,但不是我想要的,因为没有透明度.
接下来的两个尝试只是尝试新的东西,因为我想使用颜色资源.
下一行,我得到一个没有透明度的黑色.
ColorDrawable[] color = {new ColorDrawable(0x223333FF), new ColorDrawable(0xDD000000)};
Run Code Online (Sandbox Code Playgroud)
这导致最终的蓝色,而不是透明的黑色
ColorDrawable[] color = {new ColorDrawable(0x223333FF), new ColorDrawable(0x33000000)};
Run Code Online (Sandbox Code Playgroud)
我也尝试过,没有效果:
color[1].setAlpha(50);
Run Code Online (Sandbox Code Playgroud)
那么,我做错了什么?或者有更好的方法来实现这一目标吗?
你可以做到 ArgbEvaluator
ObjectAnimator animator = ObjectAnimator.ofInt(yourView, "backgroundColor", Color.RED, Color.BLUE).setDuration(3000);
animator.setEvaluator(new ArgbEvaluator());
animator.start();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3290 次 |
| 最近记录: |