During development, full screen display, custom titles (using buttons and other controls), and other requirements are often required. Today we will talk about how to control the form display of Android applications.
First, we will introduce an important method: requestWindowFeature (featrueId). Its function is to enable extended form features. A parameter is a constant defined in the Window class.
I. Enumeration Constants
1. DEFAULT_FEATURES: default system status, which is not required
2. FEATURE_CONTEXT_MENU: Enable ContextMenu. This option is enabled by default. Generally, you do not need to specify
3. FEATURE_CUSTOM_TITLE: Custom title. You must specify a custom title. For example, when the title is a button
4. FEATURE_INDETERMINATE_PROGRESS: uncertain progress
5. FEATURE_LEFT_ICON: icon on the left of the title bar
6. FEATURE_NO_TITLE: Wu title
7. FEATURE_OPTIONS_PANEL: enables the option panel function. It is enabled by default.
8. FEATURE_PROGRESS: Progress indicator Function
9. FEATURE_RIGHT_ICON: icon on the right of the title bar
Ii. Details
Default display status
Figure 1 default
1. FEATURE_CUSTOM_TITLE
This. requestWindowFeature (Window. FEATURE_CUSTOM_TITLE );
SetContentView (R. layout. main );
Figure 2 No title
This is because Featrue is not set.
After the code above, add: getWindow (). setFeatureInt (Window. FEATURE_CUSTOM_TITLE, R. layout. title );
Figure 3 custom title
The custom title is complete. It is an xml file layout.
Title. xml
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">
<ImageView android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/icon"/>
<TextView android: id = "@ + id/text"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignParentLeft = "true"
Android: text = "text"/>
</LinearLayout>
3. FEATURE_INDETERMINATE_PROGRESS
Indicates that a process is running.
Figure 4 title progress bar
Implementation Code
1. progress. xml
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">
<ProgressBar android: id = "@ + id/progress"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_vertical"
Style = "? Android: attr/progressBarStyleSmallTitle ">
</ProgressBar>
</LinearLayout>
2. Java code
This. requestWindowFeature (Window. FEATURE_INDETERMINATE_PROGRESS );
SetContentView (R. layout. main );
GetWindow (). setFeatureInt (Window. FEATURE_INDETERMINATE_PROGRESS, R. layout. progress );
SetProgressBarIndeterminateVisibility (true );
3. FEATURE_LEFT_ICON
Icon displayed on the left
Figure 5
Implementation Code
This. requestWindowFeature (Window. FEATURE_LEFT_ICON );
SetContentView (R. layout. main );
GetWindow (). setFeatureDrawableResource (Window. FEATURE_LEFT_ICON, R. drawable. icon );
4. FEATURE_NO_TITLE
Can be used for Full Screen Display
Implementation Code
This. requestWindowFeature (Window. FEATURE_NO_TITLE );
SetContentView (R. layout. main );
GetWindow (). setFlags (WindowManager. LayoutParams. FLAG_FULLSCREEN, WindowManager. LayoutParams. FLAG_FULLSCREEN );
Figure 6 full screen display
From the eternal memory