Is there a non-hacky way to change the color of just the header in an app using the Ubuntu SDK? MainView
has a headerColor
property, but that is used as the first step of gradient. Currently, I'm just putting a colored rectangle up there:
Rectangle {
id: headerBackground
height: header.height
width: header.width
anchors.top: parent.top
color: "#288369"
}
But this causes a number of issues, most notably it is incomparable with a ListView
that fills an entire page. A full example can be found in this gist.
Michael's pointer to Karma Machine's implementation did indeed point me in the right direction. The key is injecting the rectangle into the header so that it is a proper child. This can be done with the createObject() method that Michael mentioned if you have the rectangle in a separate qml file, or you can use createQmlObject with a string of QML.
Below is a much simplified example (using Tabs but the same thing is possible with a PageStack):
import QtQuick 2.0
import Ubuntu.Components 0.1
MainView {
id: mainView
width: units.gu(40)
height: units.gu(60)
Tabs {
id: tabs
Tab {
title: i18n.tr("Colored Header")
page: Page {
}
}
}
Component.onCompleted: {
tabs.tabBar.__styleInstance.headerTextSelectedColor = "white";
var component = Qt.createQmlObject(
'import QtQuick 2.0; Rectangle { anchors.fill: parent; z: -1; color: "#288369"; }',
tabs.header);
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다