Android Theme and Menu topic Menu Problems
I learned about the project of Chris Banes. Summarize theme-related small knowledge points. Let's take a look at a good example of defining a theme:
Create two files named themes in the values directory:
Themes. xml
Themes. xml (v21 ):
// Set the status bar to transparent. Set windowDrawsSystemBarBackgrounds to true.
The analysis layers are clear. The Platform is compatible with the platforms of holo and design. theme. anDream and Platform. theme. anDream. dark sub-base topic: Base. theme. anDream and Base. theme. anDream. the Theme that Dark then uses. anDream. And Theme. AnDream. Images inherited from Base. Theme. AnDream. Dark. The last one is an extension of Theme. AnDream of the program Theme. AnDream. Framed.
The level is very clear. It is a good example of topic creation. Basically all theme needs are available.
The source of the topic is Theme. AppCompat. Light. NoActionBar and Theme. AppCompat. NoActionBar. There are no light and dark themes of ActionBar In the compatible package, so that we can use toolbar freely later.
Click here to see the appcompat source code:
The Fuzzy attributes in the demo are as follows:
Overlays indicates the covering.
true
And the actionmode will be shown over the action bar instead of pushing it down. it basically lets AppCompat know that you have a toolbar located in the top of the screen and that it shoshould draw the ActionMode on top of it.
The ActionMode is displayed on the top bar instead of the menu on the screen. Tell appcompat that you have a toolbar on the top of the screen. It should draw the ActionMode onto the toolbar.
@null
Define the contentoverlay background. If the ContentOverlay background is null, it is related to the shadow under the actionbar.
@color/primary_color_translucent
Highlight font color
@android:color/black
Screen background color
true
System Operation Bar background needs to be drawn
@android:color/transparent To set the status bar to transparent, another menu is written as follows:
Android: icon
Reference A Drawable class to be used as a project icon. Android: title
Reference a string to be used as the project title. Android: showAsAction
Specify this item as the time and method for displaying the operation items in the Operation column.
The three points on the right of the toolbar are the operation overflow menu on the right of the Operation bar, which works the same as the buttons on the physical menu of the mobile phone.
To support important quick access operations, you can add android: showAsAction = "ifRoom" in the corresponding section to promote this item to the operation bar.
Android: showAsAction has a total of five attributes.
Never: never displayed. It is only displayed in the overflow list. IfRoom: It will be displayed in the Item, but if there are already four or more items, it will be hidden in the overflow list. Always: always displayed no matter whether it is overflow or not. WithText: Title is displayed. CollapseActionView: extensible Item. Small expansion:
For Android 2.3.x and earlier versions, the system calls onCreateOptionsMenu () to create the option when you open the option menu for the first time. If the application you developed is for Android 3.0 and later versions, the system will call onCreateOptionsMenu () when the Activity is started to display the project to the operation bar.
You can use the onPrepareOptionsMenu () method to perform the event modification option menu that occurs during the Activity lifecycle.
In Android 2.3.x and earlier versions, the system calls onPrepareOptionsMenu () whenever you open the option menu (press the "menu" button ().
In Android 3.0 and later versions, when a menu item is displayed in the action bar, the option menu is always in the open state. When an event occurs, if you want to perform a Menu update, you must call invalidateOptionsMenu () to request the system to call onPrepareOptionsMenu ().
To display the context operation mode by long pressing (or selecting the check box or similar UI component in the view), such as copying and pasting on top of Netease news. Some controls are implemented by default in webview.
Enable context mode for a single view
If you want to call the context operation mode only when you select a specific view, you should:
Implement the ActionMode. Callback interface. In the callback method, you can specify operations for the context operation column, respond to click events of the operation project, and process other lifecycle events in the operation mode.
Call startActionMode () when you need to display the operation bar (for example, you can press the view ().
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { // Called when the action mode is created; startActionMode() was called @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate a menu resource providing context menu items MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.context_menu, menu); return true; } // Called each time the action mode is shown. Always called after onCreateActionMode, but // may be called multiple times if the mode is invalidated. @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; // Return false if nothing is done } // Called when the user selects a contextual menu item @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.menu_share: shareCurrentItem(); mode.finish(); // Action picked, so close the CAB return true; default: return false; } } // Called when the user exits the action mode @Override public void onDestroyActionMode(ActionMode mode) { mActionMode = null; }};