You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
9.1 KiB

8 years ago
  1. ---
  2. title: Statusbar
  3. description: Control the device status bar.
  4. ---
  5. <!---
  6. # license: Licensed to the Apache Software Foundation (ASF) under one
  7. # or more contributor license agreements. See the NOTICE file
  8. # distributed with this work for additional information
  9. # regarding copyright ownership. The ASF licenses this file
  10. # to you under the Apache License, Version 2.0 (the
  11. # "License"); you may not use this file except in compliance
  12. # with the License. You may obtain a copy of the License at
  13. #
  14. # http://www.apache.org/licenses/LICENSE-2.0
  15. #
  16. # Unless required by applicable law or agreed to in writing,
  17. # software distributed under the License is distributed on an
  18. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19. # KIND, either express or implied. See the License for the
  20. # specific language governing permissions and limitations
  21. # under the License.
  22. -->
  23. |Android|iOS| Windows 8.1 Store | Windows 8.1 Phone | Windows 10 Store | Travis CI |
  24. |:-:|:-:|:-:|:-:|:-:|:-:|
  25. |[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-statusbar)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-statusbar/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-statusbar)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-statusbar/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-statusbar)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-statusbar/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-statusbar)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-statusbar/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-statusbar)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-statusbar/)|[![Build Status](https://travis-ci.org/apache/cordova-plugin-statusbar.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-statusbar)|
  26. # cordova-plugin-statusbar
  27. StatusBar
  28. ======
  29. > The `StatusBar` object provides some functions to customize the iOS and Android StatusBar.
  30. :warning: Report issues on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20Statusbar%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC)
  31. ## Installation
  32. This installation method requires cordova 5.0+
  33. cordova plugin add cordova-plugin-statusbar
  34. Older versions of cordova can still install via the __deprecated__ id
  35. cordova plugin add org.apache.cordova.statusbar
  36. It is also possible to install via repo url directly ( unstable )
  37. cordova plugin add https://github.com/apache/cordova-plugin-statusbar.git
  38. Preferences
  39. -----------
  40. #### config.xml
  41. - __StatusBarOverlaysWebView__ (boolean, defaults to true). On iOS 7, make the statusbar overlay or not overlay the WebView at startup.
  42. <preference name="StatusBarOverlaysWebView" value="true" />
  43. - __StatusBarBackgroundColor__ (color hex string, no default value). On iOS 7, set the background color of the statusbar by a hex string (#RRGGBB) at startup. If this value is not set, the background color will be transparent.
  44. <preference name="StatusBarBackgroundColor" value="#000000" />
  45. - __StatusBarStyle__ (status bar style, defaults to lightcontent). On iOS 7, set the status bar style. Available options default, lightcontent, blacktranslucent, blackopaque.
  46. <preference name="StatusBarStyle" value="lightcontent" />
  47. ### Android Quirks
  48. The Android 5+ guidelines specify using a different color for the statusbar than your main app color (unlike the uniform statusbar color of many iOS 7+ apps), so you may want to set the statusbar color at runtime instead via `StatusBar.backgroundColorByHexString` or `StatusBar.backgroundColorByName`. One way to do that would be:
  49. ```js
  50. if (cordova.platformId == 'android') {
  51. StatusBar.backgroundColorByHexString("#333");
  52. }
  53. ```
  54. Hiding at startup
  55. -----------
  56. During runtime you can use the StatusBar.hide function below, but if you want the StatusBar to be hidden at app startup, you must modify your app's Info.plist file.
  57. Add/edit these two attributes if not present. Set **"Status bar is initially hidden"** to **"YES"** and set **"View controller-based status bar appearance"** to **"NO"**. If you edit it manually without Xcode, the keys and values are:
  58. <key>UIStatusBarHidden</key>
  59. <true/>
  60. <key>UIViewControllerBasedStatusBarAppearance</key>
  61. <false/>
  62. Methods
  63. -------
  64. This plugin defines global `StatusBar` object.
  65. Although in the global scope, it is not available until after the `deviceready` event.
  66. document.addEventListener("deviceready", onDeviceReady, false);
  67. function onDeviceReady() {
  68. console.log(StatusBar);
  69. }
  70. - StatusBar.overlaysWebView
  71. - StatusBar.styleDefault
  72. - StatusBar.styleLightContent
  73. - StatusBar.styleBlackTranslucent
  74. - StatusBar.styleBlackOpaque
  75. - StatusBar.backgroundColorByName
  76. - StatusBar.backgroundColorByHexString
  77. - StatusBar.hide
  78. - StatusBar.show
  79. Properties
  80. --------
  81. - StatusBar.isVisible
  82. Permissions
  83. -----------
  84. #### config.xml
  85. <feature name="StatusBar">
  86. <param name="ios-package" value="CDVStatusBar" onload="true" />
  87. </feature>
  88. StatusBar.overlaysWebView
  89. =================
  90. On iOS 7, make the statusbar overlay or not overlay the WebView.
  91. StatusBar.overlaysWebView(true);
  92. Description
  93. -----------
  94. On iOS 7, set to false to make the statusbar appear like iOS 6. Set the style and background color to suit using the other functions.
  95. Supported Platforms
  96. -------------------
  97. - iOS
  98. Quick Example
  99. -------------
  100. StatusBar.overlaysWebView(true);
  101. StatusBar.overlaysWebView(false);
  102. StatusBar.styleDefault
  103. =================
  104. Use the default statusbar (dark text, for light backgrounds).
  105. StatusBar.styleDefault();
  106. Supported Platforms
  107. -------------------
  108. - iOS
  109. - Windows Phone 7
  110. - Windows Phone 8
  111. - Windows Phone 8.1
  112. StatusBar.styleLightContent
  113. =================
  114. Use the lightContent statusbar (light text, for dark backgrounds).
  115. StatusBar.styleLightContent();
  116. Supported Platforms
  117. -------------------
  118. - iOS
  119. - Windows Phone 7
  120. - Windows Phone 8
  121. - Windows Phone 8.1
  122. StatusBar.styleBlackTranslucent
  123. =================
  124. Use the blackTranslucent statusbar (light text, for dark backgrounds).
  125. StatusBar.styleBlackTranslucent();
  126. Supported Platforms
  127. -------------------
  128. - iOS
  129. - Windows Phone 7
  130. - Windows Phone 8
  131. - Windows Phone 8.1
  132. StatusBar.styleBlackOpaque
  133. =================
  134. Use the blackOpaque statusbar (light text, for dark backgrounds).
  135. StatusBar.styleBlackOpaque();
  136. Supported Platforms
  137. -------------------
  138. - iOS
  139. - Windows Phone 7
  140. - Windows Phone 8
  141. - Windows Phone 8.1
  142. StatusBar.backgroundColorByName
  143. =================
  144. On iOS 7, when you set StatusBar.statusBarOverlaysWebView to false, you can set the background color of the statusbar by color name.
  145. StatusBar.backgroundColorByName("red");
  146. Supported color names are:
  147. black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown
  148. Supported Platforms
  149. -------------------
  150. - iOS
  151. - Android 5+
  152. - Windows Phone 7
  153. - Windows Phone 8
  154. - Windows Phone 8.1
  155. StatusBar.backgroundColorByHexString
  156. =================
  157. Sets the background color of the statusbar by a hex string.
  158. StatusBar.backgroundColorByHexString("#C0C0C0");
  159. CSS shorthand properties are also supported.
  160. StatusBar.backgroundColorByHexString("#333"); // => #333333
  161. StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB
  162. On iOS 7, when you set StatusBar.statusBarOverlaysWebView to false, you can set the background color of the statusbar by a hex string (#RRGGBB).
  163. On WP7 and WP8 you can also specify values as #AARRGGBB, where AA is an alpha value
  164. Supported Platforms
  165. -------------------
  166. - iOS
  167. - Android 5+
  168. - Windows Phone 7
  169. - Windows Phone 8
  170. - Windows Phone 8.1
  171. StatusBar.hide
  172. =================
  173. Hide the statusbar.
  174. StatusBar.hide();
  175. Supported Platforms
  176. -------------------
  177. - iOS
  178. - Android
  179. - Windows Phone 7
  180. - Windows Phone 8
  181. - Windows Phone 8.1
  182. StatusBar.show
  183. =================
  184. Shows the statusbar.
  185. StatusBar.show();
  186. Supported Platforms
  187. -------------------
  188. - iOS
  189. - Android
  190. - Windows Phone 7
  191. - Windows Phone 8
  192. - Windows Phone 8.1
  193. StatusBar.isVisible
  194. =================
  195. Read this property to see if the statusbar is visible or not.
  196. if (StatusBar.isVisible) {
  197. // do something
  198. }
  199. Supported Platforms
  200. -------------------
  201. - iOS
  202. - Android
  203. - Windows Phone 7
  204. - Windows Phone 8
  205. - Windows Phone 8.1