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: No 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
Custom title bar content: getwindow (). setfeatureint (window. feature_custom_title, R. layout. Title );
<? 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>
Feature_indeterminate_progress
Indicates that a process is running.
<? 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>
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
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 );