Android - Setting Window Theme in Code and Manifest
Window in Android
A Window in Android is compromised of Statusbar, Title and area where User Interface for an Activity is shown.
Status Bar/ Annunciator Bar - status like battery, signal strength, data connectivity icon are shown in this area
Title - Name of the application will be shown.
Default Android Window comes with a title bar for an activity. Sometimes we might need an activity without title (Application which likes to have its own custom title) or Full Screen (like gaming apps, where user is not bothered to see the status icon).
In Android Window themes can be customized in code and in Android Manifest file.
Let us explore how we can achieve this,
Changing Android Manifest File
No title for the all screens
If you wish to apply Theme as No Title for all the activities in an application, set the android:theme as
"@android:style/Theme.NoTitleBar" in the application tag.
<application android:name="AppName"
android:icon="@drawable/icon"
android:label="@string/app_ name"
android:theme="@android:style/ Theme.NoTitleBar">
............
.............
</application>
<activity android:name="MainActivity"
android:theme="@android:style/ Theme.NoTitleBar"/>
<activity android:name="MainActivity"
android:theme="@android:style/ Theme.NoTitleBar.Fullscreen"/>
Changing Code
Before setting the layout, we need request Window feature,
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); // To Set a window with no title
// This is to set full screen without status bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.Layout.Main);
}
More Window Features
If we wish to set an icon for title, following features can be used
FEATURE_LEFT_ICON - to set an icon on left side of the title
FEATURE_RIGHT_ICON - to set an icon on right side of the title
android:icon="@drawable/icon"
android:label="@string/app_
android:theme="@android:style/
............
.............
</application>
No title for a specific activity
If you like to set an theme only specific to an activity,
android:theme="@android:style/
No annunciator/status bar for a specific activity
If you need full screen for an activity,
android:theme="@android:style/
Changing Code
Before setting the layout, we need request Window feature,
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); // To Set a window with no title
// This is to set full screen without status bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.Layout.Main);
}
More Window Features
If we wish to set an icon for title, following features can be used
FEATURE_LEFT_ICON - to set an icon on left side of the title
FEATURE_RIGHT_ICON - to set an icon on right side of the title
1 Comments:
It feels great to feature much revealing and unequalled articles on your websites. premium wordpress themes
Post a Comment
Subscribe to Post Comments [Atom]
<< Home