Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 163
Registered: ‎04-28-2012
My Device: BlackBerry 9800
My Carrier: BlackBerry

How to set an image as a background to the label?



       I want to set an image as a background to the label.Please  provide me the solution.I am able to set the background image for a conatainer using imagePaintDefintion in attachedProperty.But i am unable to set an image as a background to the label.please provide me the solution.




Posts: 692
Registered: ‎08-09-2010
My Device: Not Specified

Re: How to set an image as a background to the label?



   Please Find attachement.




feel free to press the like button on the right side to thank the user that helped you.

Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone

Re: How to set an image as a background to the label?

There is no method to provide background to a Label

Well as you said you can set image as background to a container.

Then do the same whatever you were doing, only add one more step:


Put your label inside a container(parent to label) with its preferredwidth and preferredheight property equal to that of label.


Also set label's layoutproperties: property with


horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill

 That will be all for a pseudoLabel with image set as its background.


Well you can also monitor the opacity of the image by setting opacity:  property of parent container.


A sample


        Container {
            id: labelParent
            layout: DockLayout {
            background: paint.imagePaint
            opacity: 0.5
            attachedObjects: [
                ImagePaintDefinition {
                    id: paint
                    imageSource: "asset:///images/mybackground.png"
                    repeatPattern: RepeatPattern.XY
            layoutProperties: StackLayoutProperties {
                verticalAlignment: VerticalAlignment.Center
                horizontalAlignment: HorizontalAlignment.Center
            Label {
                id: labelID
                objectName: "myLabel"
                text: "text"
                layoutProperties: DockLayoutProperties {
                    horizontalAlignment: HorizontalAlignment.Fill
                    verticalAlignment: VerticalAlignment.Fill



Ok . I know the solution is weird but as long as we don't have any method to set image as background of a label, we can use this trick.



Hope it helps







Always Success