There are several places in Android where bit arithmetic is used, such as intent Flags, custom view onmeasure (int widthmeasurespec, int heightmeasurespec), and Actionbar Setdisplayoptions, the following will understand the use of setdisplayoptions.
First look at the description of him in the document:
Public abstract voidsetdisplayoptions (int options)Added in API level 11
Set display options. This changes all display option bits at once. To change a limited subset of the display options, see setDisplayOptions(int, int) .
Parameters
| Options |
A combination of the bits defined by the Display_ constants defined in ActionBar. |
One-time settings option This method, if you want to set the section, then use the following methodPublic abstract voidsetdisplayoptions(int options, int mask)Added in API level 11
Set selected display options. The options specified by mask would be changed. To change all display option bits at once setDisplayOptions(int) .
Example:setdisplayoptions (0, Display_show_home) would disable DISPLAY_SHOW_HOME the option setdisplayoptions (Display_show_home, Display_show_home | Display_use_logo) would enable and DISPLAY_SHOW_HOME disable DISPLAY_USE_LOGO .
Parameters
| Options |
A combination of the bits defined by the Display_ constants defined in ActionBar. |
| Mask |
A bit mask declaring which display options should be changed. |
Select section to display the settings, which is set to true only if the options are set in mask to be displayed.
So here's the problem.
How do you use options and mask? Look at the following:
- Actionbar default if no settings are made, an arrow (DISPLAY_HOME_AS_UP), a logo (display_show_home), title (Display_show_title) is displayed.
- once the setdisplayoptions (int options) method is used, all the settings are changed to false,options use or operation add settings, add one to set a true-display, such as setdisplayoptions (Actionbar.display_home_as_up | Actionbar.display_show_custom), which is to set the display back arrow and CustomView
- setdisplayoptions (int options,int mask) method, that is, in the current default Actionbar settings, select a few to set, such a scenario may be the fragment inside the activity, You need to set a few actionbar options for fragment, such as
Getsupportactionbar (). Setdisplayoptions (Actionbar.display_home_as_up | Actionbar.display_show_custom, actionbar.display_home_as_up | Actionbar.display_show_title | Actionbar.display_show_home | Actionbar.display_show_custom);
Options for Actionbar.display_home_as_up | Actionbar.display_show_customMask for Actionbar.display_home_as_up | Actionbar.display_show_title | Actionbar.display_show_home | Actionbar.display_show_custom
actionbar.display_home_as_up in mask and options | Actionbar.display_show_custom, then the arrows and CustomView are set to show that the remaining actionbar.display_show_title in mask | Actionbar.display_show_home is set to hidden, that is, the corresponding setdisplayshowtitleenabled (false), other options not mentioned should be the default configuration.
As you can understand, mask and option perform the & operation, while the one that appears as true is false.
Know the principle we can use this, for example, we just show a,b,c three options,
Then use Getsupportactionbar (). Setdisplayoptions ( a|b|c );
If we need to set only the three options for b,c,d in certain conditions, such as fragment, set the b,c to display, andD to hide, then you can use Getsupportactionbar (). setdisplayoptions (b|c, b|c|d );
With this method you do not need a setting of one setdisplayshowxxx ().
Learn more to go: http://blog.csdn.net/zzp16/article/details/7956768
An explanation of the use of Android setdisplayoptions