• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Dimming the System Bars
2
3trainingnavtop=true
4
5@jd:body
6
7<div id="tb-wrapper">
8<div id="tb">
9
10<!-- table of contents -->
11<h2>This lesson teaches you to</h2>
12<ol>
13  <li><a href="#dim">Dim the Status and Navigation Bars</a></li>
14  <li><a href="#reveal">Reveal the Status and Navigation Bars</a></li>
15</ol>
16
17
18<!-- other docs (NOT javadocs) -->
19<h2>You should also read</h2>
20
21<ul>
22    <li>
23        <a href="{@docRoot}guide/topics/ui/actionbar.html">Action Bar</a> API Guide
24    </li>
25    <li>
26        <a href="{@docRoot}design/index.html">
27        Android Design Guide
28        </a>
29    </li>
30</ul>
31
32
33</div>
34</div>
35
36<p>This lesson describes how to dim the system bars (that is, the status and the navigation
37bars) on Android 4.0 (API level 14) and higher. Android does not provide a built-in way to dim the
38system bars on earlier versions.</p>
39
40<p>When you use this approach, the content doesn't resize, but the icons in the system bars
41visually recede. As soon as the user touches either the status bar or the navigation bar area of
42the screen, both bars become fully visible. The advantage of this
43approach is that the bars are still present but their details are obscured, thus
44creating an immersive experience without sacrificing easy access to the bars.</p>
45
46<h2 id="dim">Dim the Status and Navigation Bars</h2>
47
48<p>You can dim the status and notification bars on Android 4.0 and higher using the
49{@link android.view.View#SYSTEM_UI_FLAG_LOW_PROFILE} flag, as follows:</p>
50
51<pre>
52// This example uses decor view, but you can use any visible view.
53View decorView = getActivity().getWindow().getDecorView();
54int uiOptions = View.SYSTEM_UI_FLAG_LOW_PROFILE;
55decorView.setSystemUiVisibility(uiOptions);
56</pre>
57
58<p>As soon as the user touches the status or navigation bar, the flag is cleared,
59causing the bars to be undimmed. Once the flag has been cleared, your app needs to reset
60it if you want to dim the bars again.</p>
61
62<p>Figure 1 shows a gallery image in which the navigation bar is dimmed (note that the Gallery app
63completely hides the status bar; it doesn't dim it). Notice that the navigation bar (right
64side of the image) has faint white dots on it to represent the navigation controls:</p>
65
66<p class="figure" style="width:340px">
67  <img src="{@docRoot}images/training/low_profile_hide2x.png"
68  alt="system bars" />
69    <p class="img-caption"><strong>Figure 1.</strong> Dimmed system bars.</p>
70
71<p>Figure 2 shows the same gallery image, but with the system bars displayed:</p>
72
73<p class="figure" style="width:340px">
74  <img src="{@docRoot}images/training/low_profile_show2x.png"
75  alt="system bars" />
76    <p class="img-caption"><strong>Figure 2.</strong> Visible system bars.</p>
77
78    <h2 id="reveal">Reveal the Status and Navigation Bars</h2>
79
80<p>If you want to programmatically clear flags set with
81{@link android.view.View#setSystemUiVisibility setSystemUiVisibility()}, you can do so
82as follows:</p>
83
84<pre>
85View decorView = getActivity().getWindow().getDecorView();
86// Calling setSystemUiVisibility() with a value of 0 clears
87// all flags.
88decorView.setSystemUiVisibility(0);
89</pre>
90