There are several places where Android uses bit computing. Examples Intent Flags, which define view onmeasure (int widthmeasurespec, int heightmeasurespec), and Actionbar setdisplayoptions, Here's a look at how setdisplayoptions is used.
Let's take a 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. |
This method of setting options once. Suppose you want to set a 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 the section to display the settings only if the options are set in mask to be displayed. That is, set to true.
So here's the problem.
How do you use options and mask? Look at the following content
- Actionbar default assumption does not do whatever settings, will show an arrow (DISPLAY_HOME_AS_UP), a logo (display_show_home), title (Display_show_title)
- once the setdisplayoptions (int options) method is used, all the settings are changed into false,options use or operation join settings. Add one to set a true-display, for example setdisplayoptions (actionbar.display_home_as_up | Actionbar.display_show_custom), which is to set the display back arrow and CustomView
- The setdisplayoptions (int options,int mask) method, which is within the current default Actionbar settings. Select several to set. This scenario may be a fragment within the activity. There are several options to set Actionbar for fragment, for example
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. So 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.
Be able to understand this. Mask and option run the & operation at the same time as true, and one of the occurrences is false.
Knowing the principle we can use this, for example, we just want to show a,b,c three options,
Then use Getsupportactionbar (). Setdisplayoptions ( a|b|c );
Suppose we are under certain conditions, such as fragment, that we need only to set the three options for the b,c,d, B. C is set to display. d is set to hidden, then you can use Getsupportactionbar (). setdisplayoptions (b|c, b|c|d );
With this method there is no need for one setting setdisplayshowxxx ().
Know many others to go: http://blog.csdn.net/zzp16/article/details/7956768
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Android setdisplayoptions specific instructions for use