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.

333 lines
9.4 KiB

7 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. Events
  83. ------
  84. - statusTap
  85. Permissions
  86. -----------
  87. #### config.xml
  88. <feature name="StatusBar">
  89. <param name="ios-package" value="CDVStatusBar" onload="true" />
  90. </feature>
  91. StatusBar.overlaysWebView
  92. =================
  93. On iOS 7, make the statusbar overlay or not overlay the WebView.
  94. StatusBar.overlaysWebView(true);
  95. Description
  96. -----------
  97. 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.
  98. Supported Platforms
  99. -------------------
  100. - iOS
  101. Quick Example
  102. -------------
  103. StatusBar.overlaysWebView(true);
  104. StatusBar.overlaysWebView(false);
  105. StatusBar.styleDefault
  106. =================
  107. Use the default statusbar (dark text, for light backgrounds).
  108. StatusBar.styleDefault();
  109. Supported Platforms
  110. -------------------
  111. - iOS
  112. - Windows Phone 7
  113. - Windows Phone 8
  114. - Windows Phone 8.1
  115. StatusBar.styleLightContent
  116. =================
  117. Use the lightContent statusbar (light text, for dark backgrounds).
  118. StatusBar.styleLightContent();
  119. Supported Platforms
  120. -------------------
  121. - iOS
  122. - Windows Phone 7
  123. - Windows Phone 8
  124. - Windows Phone 8.1
  125. StatusBar.styleBlackTranslucent
  126. =================
  127. Use the blackTranslucent statusbar (light text, for dark backgrounds).
  128. StatusBar.styleBlackTranslucent();
  129. Supported Platforms
  130. -------------------
  131. - iOS
  132. - Windows Phone 7
  133. - Windows Phone 8
  134. - Windows Phone 8.1
  135. StatusBar.styleBlackOpaque
  136. =================
  137. Use the blackOpaque statusbar (light text, for dark backgrounds).
  138. StatusBar.styleBlackOpaque();
  139. Supported Platforms
  140. -------------------
  141. - iOS
  142. - Windows Phone 7
  143. - Windows Phone 8
  144. - Windows Phone 8.1
  145. StatusBar.backgroundColorByName
  146. =================
  147. On iOS 7, when you set StatusBar.statusBarOverlaysWebView to false, you can set the background color of the statusbar by color name.
  148. StatusBar.backgroundColorByName("red");
  149. Supported color names are:
  150. black, darkGray, lightGray, white, gray, red, green, blue, cyan, yellow, magenta, orange, purple, brown
  151. Supported Platforms
  152. -------------------
  153. - iOS
  154. - Android 5+
  155. - Windows Phone 7
  156. - Windows Phone 8
  157. - Windows Phone 8.1
  158. StatusBar.backgroundColorByHexString
  159. =================
  160. Sets the background color of the statusbar by a hex string.
  161. StatusBar.backgroundColorByHexString("#C0C0C0");
  162. CSS shorthand properties are also supported.
  163. StatusBar.backgroundColorByHexString("#333"); // => #333333
  164. StatusBar.backgroundColorByHexString("#FAB"); // => #FFAABB
  165. On iOS 7, when you set StatusBar.statusBarOverlaysWebView to false, you can set the background color of the statusbar by a hex string (#RRGGBB).
  166. On WP7 and WP8 you can also specify values as #AARRGGBB, where AA is an alpha value
  167. Supported Platforms
  168. -------------------
  169. - iOS
  170. - Android 5+
  171. - Windows Phone 7
  172. - Windows Phone 8
  173. - Windows Phone 8.1
  174. StatusBar.hide
  175. =================
  176. Hide the statusbar.
  177. StatusBar.hide();
  178. Supported Platforms
  179. -------------------
  180. - iOS
  181. - Android
  182. - Windows Phone 7
  183. - Windows Phone 8
  184. - Windows Phone 8.1
  185. StatusBar.show
  186. =================
  187. Shows the statusbar.
  188. StatusBar.show();
  189. Supported Platforms
  190. -------------------
  191. - iOS
  192. - Android
  193. - Windows Phone 7
  194. - Windows Phone 8
  195. - Windows Phone 8.1
  196. StatusBar.isVisible
  197. =================
  198. Read this property to see if the statusbar is visible or not.
  199. if (StatusBar.isVisible) {
  200. // do something
  201. }
  202. Supported Platforms
  203. -------------------
  204. - iOS
  205. - Android
  206. - Windows Phone 7
  207. - Windows Phone 8
  208. - Windows Phone 8.1
  209. statusTap
  210. =========
  211. Listen for this event to know if the statusbar was tapped.
  212. window.addEventListener('statusTap', function() {
  213. // scroll-up with document.body.scrollTop = 0; or do whatever you want
  214. });
  215. Supported Platforms
  216. -------------------
  217. - iOS