Android Canvas 改变背景颜色

我有一个有两个 View 的应用

<com.myexample.ui.view.BackgroundView 
        android:id="@+id/id_draw_canvas_classroom" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_marginBottom="3dp" 
        android:layout_marginLeft="5dp" 
        android:layout_marginRight="5dp" 
        android:layout_marginTop="3dp" 
        android:layout_weight="1" 
        android:background="#FFFFFFFF" /> 
 
    <com.myexample.ui.view.FrontView 
        android:id="@+id/id_draw_canvas_user" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_marginBottom="3dp" 
        android:layout_marginLeft="5dp" 
        android:layout_marginRight="5dp" 
        android:layout_marginTop="3dp" 
        android:layout_weight="1" 
        android:background="#00000000" /> 

这个view是重叠的,我在后台的view中加载了一段时间的信息。在那段时间里,我想将 FrontView 设置为白色,然后(当背景完成加载时)变为透明。

在 FrontView 中,我有一个带有位图的 Canvas 。正在工作,如果我想将背景设置为透明,我可以这样做

canvas.drawColor(0); 

设置背景为白色

canvas.drawColor(-1); 

如果无法将白色更改为透明,试试这个:

/* 
* A = Alpha a.k.a. transparency 
* R = Red color 
* G = Green color 
* B = Blue color 
* 
* All of them have a range from 0 to 255 
*/ 
canvas.drawARGB(0, 225, 225, 255); 

或者

canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); 

第一个选项更好,因为它更精确,例如,如果您想将其设置得不那么透明。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值