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
1. feature_custom_title
This. requestwindowfeature (window. feature_custom_title );
Setcontentview (R. layout. Main );
This is because featrue is not set.
After the code above, add: getwindow (). setfeatureint (window. feature_custom_title, R. layout. Title );
The custom title is complete. It is an XML file layout.
Title. xml
1 <? XML version = "1.0" encoding = "UTF-8"?> 2 <linearlayout 3 xmlns: Android = "http://schemas.android.com/apk/res/android" 4 Android: layout_width = "wrap_content" 5 Android: layout_height = "wrap_content"> 6 7 <imageview Android: layout_width = "wrap_content" 8 Android: layout_height = "wrap_content" 9 Android: src = "@ drawable/icon"/> 10 <textview Android: id = "@ + ID/text" 11 Android: layout_width = "wrap_content" 12 Android: layout_height = "wrap_content" 13 Android: layout_alignparentleft = "true" 14 Android: TEXT = "text"/> 15 16 </linearlayout>
3. feature_indeterminate_progress
Indicates that a process is running.
Implementation Code
1. Progress. xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 android:layout_width="wrap_content" 5 android:layout_height="wrap_content"> 6 <ProgressBar android:id="@+id/progress" 7 8 android:layout_width="wrap_content" 9 10 android:layout_height="wrap_content" 11 12 android:layout_gravity="center_vertical"13 style="?android:attr/progressBarStyleSmallTitle">14 15 </ProgressBar>16 </LinearLayout>
2.Java code
1 this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);2 setContentView(R.layout.main);3 4 5 getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);6 setProgressBarIndeterminateVisibility(true);
3. feature_left_icon
Icon displayed on the left
Implementation Code
1 this.requestWindowFeature(Window.FEATURE_LEFT_ICON);2 setContentView(R.layout.main);3 4 getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);
4. feature_no_title
Can be used for Full Screen Display
Implementation Code
1 this.requestWindowFeature(Window.FEATURE_NO_TITLE);2 setContentView(R.layout.main);3 4 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Figure 6 full screen display
Turn: http://www.cnblogs.com/salam/archive/2010/11/30/1892143.html