android Window Introduction

Source: Internet
Author: User
<span id="Label3"></p><span style="font-size:14px"><span style="font-size:14px">dialog is the Application class window whose subclasses are mostly changed to child windows<br>Popupwindow is the App class window that changes to a child window when it is displayed<br></span></span><p><p><span style="font-size:14px">Contextwindow is also the Application class window</span></p></p><p><p><span style="font-size:14px">Optionmenu is the Application class window</span><br></p></p><p><p></p></p><p><p><br></p></p><p><p><span style="font-size:14px; color:#FF0000">The root view of the App Class View is Decorview</span><br></p></p><span style="font-size:14px"><span style="font-size:14px">Menu Important Class Introduction:<br><span style="color:#FF0000"></span>Menu: A interface describes the interface that a menu should have. here the menu refers to the entire menu instead of an entry<br>Menubuilder is its true realization<br><span style="color:#FF0000">MenuItem</span>: A interface describes the action interface that a menu entry should have Menuitemimpl is the data that implements the entries saved in the class<br><span style="color:#FF0000">Contextmenubuilder</span>: There is a ArrayList (menuitemimpl) variable in this class that holds the entry information for the entire menu<br>Expands the menubuilder to increase the ContextMenu characteristics.<br><span style="color:#FF0000">Menudialoghelper</span>: Provides an action to display menu<br><br>ContextMenu Display Process:<br>Long press The->view class Performlongclick ()->showcontextmenu (), call Mparent.showcontextmenuforchild () at this point the root view is (DecorView)<br>That is, Decorview's showcontextmenuforchild ()->contextmenubuilder class, show (), calls the view Class's Createcontextmenu () in Show () method to create a detailed entry<br></span></span><p><p><span style="font-size:14px">Finally call the show () method of the Menudialoghelper class to complete the display</span></p></p><p><p><span style="font-size:14px"><br></span></p></p><p><p><span style="font-size:14px">3 Ways to create optionmenu:</span></p></p><p><p><span style="font-size:14px">The Preparepanel method of Phonewindow is called when the menu key is pressed</span></p></p><p><p><span style="font-size:14px"></span></p></p><pre name="code" class="java"> Public final Boolean Preparepanel (panelfeaturestate st, keyevent event) {//already prepared (isprepared'll be Reset to False Later) if (st.isprepared) return true; If (mpreparedpanel! = Null) && (mpreparedpanel! = St)) {//another Panel is prepared and possibly ope n, so close it closepanel (mpreparedpanel, false); } final Callback cb = Getcallback (); cb==activity if (cb! = Null) {//call oncreatepanelview to display a custom optionmenu St.createdpanelview = C B.oncreatepanelview (st.featureid); } if (st.createdpanelview = = Null) {//init The panel state ' s Menu--return false if Init failed if (st.menu = = Null) {if (!initializepanelmenu (st) | | | (st.menu = = Null)) {return false; }//call callback, and return if it doesn ' t want to display Menu//invoke Activity's oncreateoptio Nmenu.Create a menu if (CB = = Null) | |!cb.oncreatepanelmenu (st.featureid, st.menu)) {//ditch th E menu created above St.menu = null; Return false; }}//Callback and return if the Callback does not want to show the Menu//onpreparepane L Custom Optionmenu if (!cb.onpreparepanel (st.featureid, st.createdpanelview, st.menu)) {return fals E }//Set the proper keymap keycharactermap Kmap = keycharactermap.load (event! = null? Event.getdevi CeId (): 0); St.qwertymode = Kmap.getkeyboardtype ()! = keycharactermap.numeric; St.menu.setQwertyMode (st.qwertymode); }//Set other state st.isprepared = true; st.ishandled = false; Mpreparedpanel = st; Return true; }</pre>First look at a few concepts<p><p></p></p><p><p><span style="font-size:14px"></span></p></p><p><p><span style="font-size:14px"><br></span></p></p><p><p><span style="font-size:14px">Analyze the above code: you can see that there are 3 comments<br></span></p></p><p><p><span style="font-size:14px">There are 3 different ways to create a menu in these 3 notes</span></p></p><p><p><span style="font-size:14px">The callback here is the activity (activity implements the callback Interface)<br></span></p></p><p><p><span style="font-size:14px">1.<span style="color:#FF0000">Oncreatepanelview</span></span></p></p><p><p><span style="font-size:14px">Acitivity's</span> <span style="font-size:14px">Oncreatepanelview</span> <span style="font-size:14px">Method</span></p></p><p><p><span style="font-size:14px"></span></p></p><pre name="code" class="java"><pre name="code" class="java"> Public View Oncreatepanelview (int featureid) { return null; }</pre></pre>St.createdpanelview = Cb.oncreatepanelview (st.featureid);<p><p></p></p><p><p><span style="font-size:14px">By overriding <span style="font-size:14px">Oncreatepanelview</span> We can change the value of <span style="font-size:14px">Createdpanelview</span> to implement custom Optionmenu</span></p></p><p><p><span style="font-size:14px"><br></span></p></p><p><p><span style="font-size:14px">2.cb. <span style="color:#FF0000">Oncreatepanelmenu</span> (st.featureid, St.menu)</span></p></p><p><p><span style="font-size:14px"></span></p></p><pre name="code" class="java"><pre name="code" class="java">public boolean oncreatepanelmenu (int featureid, menu Menu) { if (featureid = = Window.feature_options_panel) { return Oncreateoptionsmenu (menu); } return false; }</pre></pre>Calling the Oncreateoptionmenu method here is also the most common way we create Optionmenu<br><p><p></p></p><p><p><span style="font-size:14px">This provides a menu object for us to operate on, and for background view, it uses the default</span></p></p><p><p><span style="font-size:14px">Look again:</span></p></p><pre name="code" class="java"><pre name="code" class="java">if (CB = = Null) | |!cb.oncreatepanelmenu (st.featureid, st.menu)) { //ditch The menu created above st.menu = null ; return false; }</pre></pre><br><p><p></p></p><p><p><span style="font-size:14px">Oncreatepanelmenu The default return value is False in the If statement, which is true</span></p></p><p><p><span style="font-size:14px">So execute St.menu = null;</span></p></p><p><p><span style="font-size:14px">So we rewrite <span style="font-size:14px">oncreatepanelmenu</span> Be sure to return to Ture</span></p></p><p><p><span style="font-size:14px">3.<span style="color:#FF0000">Onpreparepanel</span></span></p></p><p><p><span style="font-size:14px"></span></p></p><pre name="code" class="java"><pre name="code" class="java">public boolean Onpreparepanel (int featureid, view view, menu Menu) { if (featureid = = Window.feature_options_panel &am p;& menu = Null) { Boolean goforit = Onprepareoptionsmenu (menu); return Goforit && menu.hasvisibleitems (); } return true; }</pre></pre><br>Here we directly rewrite the target of Onpreparepanel for Createdpanelview (view) and menu (menu) to custom Optionmenu<br><p><p></p></p><p><p><br></p></p><p><p>android Window Introduction</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.