02-08-2013 06:54 AM
HI, I started developing my app using cascades, and I am encountering some strange situations.
I want a button which has text of white color and an image as a background.
I am looking at this button: https://developer.blackberry.com/cascades/referenc
-- and it seems it will not satisfy my requirements??
What to do in such a case???
Thank you.
02-08-2013 09:07 AM
Container {
background: backgroundImagePaint.imagePaint
onTouch: {
if (event.isUp()) {
// Handle click here.
}
}
Label {
text: "Button text"
}
attachedObjects: [
ImagePaintDefinition {
id: backgroundImagePaint
repeatPattern: RepeatPattern.Fill
imageSource: "asset:///images/image.png.amd"
}
]
}
02-08-2013 09:14 AM
02-08-2013 09:20 AM
By using the ImagePaintDefinition you can assign it directly to the Container.background property. I think this is the advantage.
Furthermore, highlighting of the button can also be implemented.
Container {
onTouch: {
if (event.isDown() || event.isMove()) {
// Focused
} else if (event.isUp()) {
// Unfocused
} else if (event.isCancel()) {
// Unfocused
}
}
}
02-08-2013 09:36 AM - edited 02-08-2013 09:36 AM
Hi, this is my code
Container {
background: backgroundImagePaint.imagePaint
horizontalAlignment: HorizontalAlignment.Center
onTouch: {
if (event.isDown() || event.isMove()) {
// Focused
background: backgroundImagePaintHighlighted.imagePaint
textLabel="test";
} else if (event.isUp()) {
background: backgroundImagePaint.imagePaint
// Unfocused
} else if (event.isCancel()) {
background: backgroundImagePaint.imagePaint
// Unfocused
}
}
Label {
id: textLabel
text: "Button text"
textStyle.color: Color.create("#ffffffff")
}
attachedObjects: [
ImagePaintDefinition {
id: backgroundImagePaint
repeatPattern: RepeatPattern.Fill
imageSource: "asset:///btn-green.png"
},
ImagePaintDefinition {
id: backgroundImagePaintHighlighted
repeatPattern: RepeatPattern.Fill
imageSource: "asset:///btn-darkgreen.png"
}
]
}but it seems not to be working.... does not have a "selected" effect on the button... actually, I think I never enter the isDown scope since the text of the label does not change either... help appreciated...
02-08-2013 09:42 AM
You have to assign the text to textLabel.text.
textLabel.text="test"
02-08-2013 09:50 AM
02-08-2013 10:04 AM
Container {
background: backgroundImagePaint.imagePaint
horizontalAlignment: HorizontalAlignment.Center
Container {
onTouch: {
if (event.isDown() || event.isMove()) {
// Focused
background: Color.create("#88FFFFFF")
} else if (event.isUp()) {
background: Color.create("#00FFFFFF")
// Unfocused
} else if (event.isCancel()) {
background: Color.create("#00FFFFFF")
// Unfocused
}
}
Label {
id: textLabel
text: "Button text"
textStyle.color: Color.create("#ffffffff")
}
}
attachedObjects: [
ImagePaintDefinition {
id: backgroundImagePaint
repeatPattern: RepeatPattern.Fill
imageSource: "asset:///btn-green.png"
}
]
}
Use a second container.
02-08-2013 10:15 AM
02-24-2013 11:18 AM
Hi, brother, have you solved it? If not, you can try the following code which works well:
import bb.cascades 1.0
Page {
Container {
layout: StackLayout {}
background: backgroundPaint.imagePaint
attachedObjects: [
ImagePaintDefinition {
id: backgroundPaint
imageSource: "asset:///images/background.png"
}
]
Button{
id: defaultButton
text: "default button"
preferredWidth: 300
}
Container {
id: customButton
background: Color.Gray
preferredHeight: 70
preferredWidth: 300
layout: StackLayout {}
Label {
text: "custom button"
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
}
onTouch: {
if (event.isDown() || event.isMove()) {
// Focused, change the background
customButton.background = Color.Blue;
} else if (event.isUp()) {
customButton.background = Color.Gray;
// Unfocused
} else if (event.isCancel()) {
customButton.background = Color.Gray;
}
}
}
}
}