Android Question how to get android.graphics.drawable.Drawable

ArminKH

Well-Known Member
hi i want to get a "android.graphics.drawable.Drawable"
but b4a does't support this
this is my code in class module
B4X:
Public Sub setMainActionDrawable(Drawable As BitmapDrawable)
    Imageview1.Background = Drawable
End Sub
but when i want to set a background image to this image view by using this code(in main activity)
B4X:
dim xml as XmlLayoutBuilder
Tools.MainActionDrawable = xml.GetDrawable("icon")
then error message said
B4X:
error: incompatible types: android.graphics.drawable.BitmapDrawable cannot be converted to anywheresoftware.b4a.objects.drawable.BitmapDrawable
what is the solution?
how i can set the image view background by using this sub with xmllayoutbuilder?
 
Last edited:

ArminKH

Well-Known Member
Try this:
B4X:
Dim bd As BitmapDrawable = xml.GetDrawable(...)
Tools.MainActionDrawable = bd
Does it work?
yes but my codes is using your solution and it is seems correct
but why don't work?
 
Last edited:
Upvote 0

mshafiee110

Active Member
Licensed User
Longtime User
@Erel
@ArminKH
Hi
I solve this,
B4X:
Public Sub setMainActionDrawable(xDrawable As String)
    Imageview1.Background = x.GetDrawable("xDrawable")
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Public Sub setMainActionDrawable(xDrawable As String)
Imageview1.Background = x.GetDrawable(
"xDrawable")
End Sub
You are setting a drawable named xDrawable. No matter what you give in the parameter. it will be ignored.

B4X:
Public Sub setMainActionDrawable(xDrawable As String)
    Imageview1.Background = x.GetDrawable(xDrawable)
End Sub
here the given string is used to get the drawable.
 
Upvote 0

mshafiee110

Active Member
Licensed User
Longtime User
You are setting a drawable named xDrawable. No matter what you give in the parameter. it will be ignored.

B4X:
Public Sub setMainActionDrawable(xDrawable As String)
    Imageview1.Background = x.GetDrawable(xDrawable)
End Sub
here the given string is used to get the drawable.
Yes ,of course .
xDrawable only is a string for define name of picture.
 
Upvote 0

ArminKH

Well-Known Member
You are setting a drawable named xDrawable. No matter what you give in the parameter. it will be ignored.

B4X:
Public Sub setMainActionDrawable(xDrawable As String)
    Imageview1.Background = x.GetDrawable(xDrawable)
End Sub
here the given string is used to get the drawable.
it is typo mistake ;)
 
Upvote 0
Top