Android Question Getting views color

tufanv

Expert
Licensed User
Longtime User
hello'

I need the panels color. .color is write only. I need a sub to get the color of a view. I searched the forum and found this post.

https://www.b4x.com/android/forum/posts/134379/

But when i use getviewscolor(panel1) , panel 1 goes white. Every view goes white when i use get color on it. Is it an outdated solution, can we have an updated sub to get a color's view. ?

this is what happens
Screenshot_2017_01_22_16_57_41.png
 
Last edited:
This code should still work. Make sure that you are not using the same canvas for anything else.

If it doesn't work for you then please upload a small project with the code.
in this example , when we use getviewscolor the red panels most portion is painted to black ( or the color of activity )

Attached it.
 

Attachments

Upvote 0
It is indeed related to a change in the way views handle their background. I've fixed this issue in Canvas.DrawViewable code.
For now you can use this instead:
Code: Copy
Sub GetViewsColor(v As View) As Int
   Dim jo As JavaObject = v.Background
   Dim b As Rect = jo.RunMethod("copyBounds", Null)
   Dim destRect As Rect
   destRect.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
   cvs.DrawDrawable(v.Background, destRect)
   jo.RunMethod("setBounds", Array(b))
   Return cvs.Bitmap.GetPixel(5dip, 5dip)
End Sub
 
Upvote 0
It is indeed related to a change in the way views handle their background. I've fixed this issue in Canvas.DrawViewable code.
For now you can use this instead:
Code: Copy
Sub GetViewsColor(v As View) As Int
   Dim jo As JavaObject = v.Background
   Dim b As Rect = jo.RunMethod("copyBounds", Null)
   Dim destRect As Rect
   destRect.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
   cvs.DrawDrawable(v.Background, destRect)
   jo.RunMethod("setBounds", Array(b))
   Return cvs.Bitmap.GetPixel(5dip, 5dip)
End Sub



I have got a problem with this. When I use
if getviewscolor(lbl1)= colors.transparent ıt makes problem. it does not recognize the color as transparent so i can't achieve what i want. Is there a fix for this
 
Upvote 0
by thw way if i use getviewscolor(lbl1)=colors.green it is not working but if i use colors.rgb(..) it works. So i think it does not recognize when we write colors.green or colors.red , we have to put in rgb . But what can i write for rgb for transparent ?
 
Upvote 0
Back
Top