Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Two Ways to Set Fullscreen in Android Activity and Analysis of System Theme Attributes

Tech 1

Setting an Activity to hide the title bar or display fullscreen is common in development, as phone screens are limited in size. Sometimes we want to show more information by removing unnecessary interface elements, such as the title bar and status bar; sometimes for simplicity and aesthetics. Here are two common methods (similar to most attribute settings in Android development):

(1) Static Registration in XML

Set the android:theme attribute under the corresponding Activity node in AndroidManifest.xml. The attribute value usually starts with @android:style/Theme., for example: android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen". Let's see the differences and effects of these themes (using Android 4.4.2 as an example):

Add a TextView to help observe:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Fullscreen Settings and Theme Attribute Parsing"
    android:textSize="20sp" />
<!-- Only font size is set, no font color -->

Note: Only font size is set, not font color. This will be relevant later.

<activity
    android:name="com.example.fullscreen.TestActivity"
    android:label="@string/title_activity_test"
    android:theme="@android:style/Theme.[value below]"
    android:icon="@drawable/ic_launcher"
    android:screenOrientation="portrait">
    <!-- android:theme attribute added -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

(1) No theme attribute specified

(2) Black Theme

  • Theme.Black: Black theme, gray title bar, no icon (even if set), status bar present, inverted text color.
  • Theme.Black.NoTitleBar: Black theme, no title bar, status bar present, inverted text.
  • Theme.Black.NoTitleBar.Fullscreen: Black theme, no title bar, no status bar, inverted text.

(3) Light Theme (only color differs from Black)

  • Theme.Light: White theme, gray title bar, no icon, status bar present, black text.
  • Theme.Light.NoTitleBar: White theme, no title bar, status bar present, black text.
  • Theme.Light.NoTitleBar.Fullscreen: White theme, no title bar, no status bar, black text.

From the above, we can see: "Theme" is a domain, "NoTitleBar" means no title bar, "FullScreen" means no status bar.

(4) Wallpaper Theme

  • Theme.Wallpaper: Similar to black theme, but background is the phone wallpaper.
  • Similarly, Theme.Wallpaper.NoTitleBar and Theme.Wallpaper.NoTitleBar.Fullscreen.

(5) Translucent Theme

  • Theme.Translucent: Semi-transparent (appears transparent in affect).
  • Similar, Theme.Translucent.NoTitleBar and Theme.Translucent.NoTitleBar.Fullscreen.

(6) Holo Theme

  • Theme.Holo (with .NoActionBar or .NoActionBar.Fullscreen): Holo style, black background, blue title bar bottom, title bar can show icon, inverted text.
  • Theme.Holo.Light (with .NoTitleBar or .NoTitleBar.Fullscreen): Holo style, silver background, title bar can show icon, black text.
  • Theme.Holo.Wallpaper (with .NoTitleBar): Holo style, wallpaper background, title bar has blue bottom border.

Note:

  • There is no Theme.Holo.Black; Theme.Holo is black background by default.
  • There is no Theme.Holo.Translucent.

In summary, remember keywords like Black, Light, Holo, Translucent, Wallpaper, NoTitleBar, NoActionBar, FullScreen, and their meanings. When needed, find the appropriate combination from the system list. For unsupported combinations, you must define a custom theme.

(2) Setting at Activity Loading

In the onCreate() method of the Activity, before calling setContentView(), use the following statements:

this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Hide the application title bar (Activity label)
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN); // Hide the system status bar

Note: These must be set before setContentView(), otherwise they have no effect, because setContentView() sets the components displayed in the "View drawing area", while the status bar and title bar are outside this area (application area/screen).

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.