我正在尝试在我的应用中实现基本的后退按钮。
我在网页中使用网页浏览。
添加了我在论坛中找到的按钮和代码。
Button {
id: button1
text: "Back"
onClicked: {
WebView.goBack();
}
我错过了什么吗?
答案 0 :(得分:0)
这是简单的代码
main.qml
import bb.cascades 1.0
NavigationPane {
id: nav
Page {
id: pg
titleBar: TitleBar {
id: tb
title: "Mini Web Browser"
}
Container {layout:StackLayout {
orientation:LayoutOrientation.TopToBottom
}
Container {
layout:StackLayout {
orientation:LayoutOrientation.LeftToRight
}
TextField {
id:tf
hintText: "Enter you Url"
inputMode: TextFieldInputMode.Url
input.submitKey: SubmitKey.Go
layoutProperties: StackLayoutProperties {
spaceQuota: 5
}
}
Button {
id:go
imageSource: "asset:///ic_done.png"
layoutProperties: StackLayoutProperties {
spaceQuota: 1
}
onClicked: {
console.log(tf.text);
console.log(myWebView.urlChanged(tf.text))
}
}
}
ScrollView {
scrollViewProperties.pinchToZoomEnabled: true
scrollViewProperties.scrollMode: ScrollMode.Both
WebView {
id:myWebView
url: "https://www.google.com/search?q="+tf.text
settings.devicePixelRatio: 1.0
onLoadingChanged: {
if (loadRequest.status == WebLoadStatus.Started ) {
statusLabel.setText("Loading start..................")
tb.title=myWebView.title
statusLabel.visible=true
}
else if (loadRequest.status == WebLoadStatus.Succeeded ) {
statusLabel.setText("Loading finished.")
statusLabel.visible=false
tb.title=myWebView.title
}
else if (loadRequest.status == WebLoadStatus.Failed ) {
statusLabel.setText("Load failed.")
}
}
}
}
ProgressIndicator {
id: pi
verticalAlignment: VerticalAlignment.Fill
fromValue:0
toValue: 100
value:myWebView.loadProgress
onValueChanged: {
if(value<100)
pi.visible=true
else if(value== 100)
pi.visible=false
}
}
Label{
id: statusLabel
verticalAlignment: VerticalAlignment.Bottom
horizontalAlignment: HorizontalAlignment.Fill
text: "ram"
//visible:
textStyle.textAlign: TextAlign.Left
textStyle.color: Color.Black
}
}
actions:[
ActionItem {
enabled: myWebView.canGoBack
title: "Back"
ActionBar.placement: ActionBarPlacement.OnBar
imageSource: "asset:///ic_previous.png"
onTriggered: {
myWebView.goBack()
}
},
ActionItem {
title: "Forword"
enabled: myWebView.canGoForward
ActionBar.placement: ActionBarPlacement.OnBar
imageSource: "asset:///ic_next.png"
onTriggered: { myWebView.goForward();
}
},
ActionItem {
title:myWebView.loading ? "Stop" : "Reload"
ActionBar.placement: ActionBarPlacement.OnBar
imageSource:myWebView.loading ? "asset:///ic_cancel.png" : "asset:///ic_rotate.png"
onTriggered: {myWebView.loading ? myWebView.stop():myWebView.reload();
}
}
]
}
}
答案 1 :(得分:0)
这是我用于帮助页面的内容,该页面从assets目录加载HTML,其中可能包含指向应用程序网站的链接以获取其他信息。彼得的评论可能是你的解决方案。在这种情况下,后退按钮放在TitleBar中,但它可以很容易地放在操作栏,溢出菜单或其他位置。
import bb.cascades 1.0
Page {
titleBar: TitleBar {
title: "Help"
scrollBehavior: TitleBarScrollBehavior.NonSticky
dismissAction: ActionItem {
title: "Close"
onTriggered: {
helpSheet.close();
}
imageSource: "asset:///images/ic_cancel.png"
}
acceptAction: ActionItem {
title: "Back"
enabled: webView.canGoBack
onTriggered: {
webView.goBack();
}
}
}
id: helpPage
objectName: "helpSheet"
ScrollView {
Container {
layout: StackLayout {
}
WebView {
id: webView
url: "local:///assets/help.html"
layoutProperties: StackLayoutProperties {
}
topMargin: 21.0
}
}
}
}