Android: full screen setting + heading + only program title bar (Application and activity settings)

Source: Internet
Author: User

In actual application development, we sometimes need to set the activity to full screen display. Generally, we can set the full screen display effect in two ways:

First, you can set it in the code,

Second, set full screen through the manifest configuration file.

 

1. Set it before setcontentview in oncreate code (as follows)
View plaincopy to clipboardprint?
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );

// Cancel the title
Requestwindowfeature (window. feature_no_title );
// Cancel the status bar
Getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen,
Windowmanager. layoutparams. flag_fullscreen );


Setcontentview (R. layout. Main );
}

However, you must note that if you set it in the Code, the two sections of code with no title and full screen should be placed in setcontentview (R. layout. main) (interface rendering, but it won't work if the screen is finished) before this code. Otherwise, an error is reported.

 

Second, set it in the manifest configuration file.

  • Method 1

① Create a theme. xml file in the Res/values directory (for style placement)

<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<! -- Name is the name of the style, and parent inherits the parent style -->
<Style name = "theme_fullscreen" parent = "Android: theme. Black">
<Item name = "Android: windownotitle"> true </item> <! -- Set no title -->
<Item name = "Android: windowfullscreen">? Android: windownotitle </item> <! --Whether to fill in the slow screen and reference the Android: windownotitle Value? Android: windownotitle, depending on the value of Android: windownotitle -->
</Style>
</Resources>

② <Activity Android: Name = ". login. loginactivity" Android: theme = "@ style/theme_fullscreen"/>

  • Method 2

View plaincopy to clipboardprint?
<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. andyidea"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Uses-SDK Android: minsdkversion = "8"/>
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<Activity Android: Name = ". login. loginactivity"
Android: theme = "@ Android: style/theme. notitlebar. fullscreen"
Android: Label = "@ string/app_name">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
</Application>
</Manifest>

 

 

 Set no title for the entire application only in the program title bar.

(Please mail to freeget.one@gmail.com for the latest strong software.)

Third: This is not commonly used in general applications. It is to create a style. xml file under the Res/values directory.For example:
 

<?xml version="1.0" encoding="UTF-8" ?>  <resources><style name="theme_notitle"><item name="android:windowNoTitle">true</item></style></resources>

In this way, we customize a style, which is equivalent to a topic and then defined in the androidmanifest. xml file.

<application android:icon="@drawable/icon"  android:label="@string/app_name"android:theme="@style/theme_notitle">

In this way, the title bar can be removed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.