Android Custom Keys

Source: Internet
Author: User
<span id="Label3"></p>Android comes with a menu key, a return key, and a search key rewrite from: http://blog.sina.com.cn/s/blog_7cb9b3b801015yk8.html<p><p><span>Return key</span></p></p><p><p><strong>public void onbackpressed () {</strong></p></p><p><p><strong>TODO auto-generated Method Stub</strong></p></p><p><p><strong>Toast toast=toast.maketext (config.this, "this key has broken down ... \ n Press Next to it! ", 3000);</strong></p></p><p><p><strong>Toast.setgravity (gravity.center, 0, 0);</strong></p></p><p><p><strong>Toast.show ();</strong></p></p><p><p><strong>}</strong></p></p><p><p><span>Search Key</span></p></p><p><p><strong>@Override</strong></p></p><p><p><strong>Public Boolean onsearchrequested () {</strong></p></p><p><p><strong>TODO auto-generated Method Stub</strong></p></p><p><p><strong>Toast.maketext (config.this, "i've been broken ... ", +). Show ();</strong></p></p><p><p><strong>return super.onsearchrequested ();</strong></p></p><p><p><strong>}</strong></p></p><p><p><span>Menu key</span></p></p><p><p><strong>@Override</strong></p></p><p><p><strong>public boolean Oncreateoptionsmenu (menu Menu) {</strong></p></p><p><p><strong>TODO auto-generated Method Stub</strong></p></p><p><p><strong>Menu.add (0, 0, 0, "exit");</strong></p></p><p><p><strong>return Super.oncreateoptionsmenu (menu);</strong></p></p><p><p><strong>}</strong></p></p><p><p><strong>@Override</strong></p></p><p><p><strong>public boolean onoptionsitemselected (MenuItem Item) {</strong></p></p><p><p><strong>TODO auto-generated Method Stub</strong></p></p><p><p><strong>Switch (item.getitemid ()) {</strong></p></p><p><p><strong>Case 0:</strong></p></p><p><p><strong>Finish ();</strong></p></p><p><p><strong>Break</strong></p></p><p><p><strong>    </strong> <strong>} </strong></p></p><p><p><strong>return super.onoptionsitemselected (item);</strong></p></p><p><p><strong>}</strong></p></p><p><p></p></p><p><p><strong><span style= "COLOR: #ff0000" > First disable the Home button, and then in the onkeydown process key values, Click the Home button when the program is closed </SPAN></strong></p></p><p><p></p></p><p><p><strong>public boolean OnKeyDown (int keycode, keyevent Event)</strong></p></p><p><p><strong>{</strong></p></p><p><p><strong>TODO auto-generated Method Stub</strong></p></p><p><p><strong>If (keyevent.keycode_home==keycode)</strong></p></p><p><p><strong>Android.os.Process.killProcess (android.os.Process.myPid ());</strong></p></p><p><p><strong>return Super.onkeydown (keycode, event);</strong></p></p><p><p><strong>}</strong></p></p><p><p><strong>@Override</strong></p></p><p><p><strong>public void Onattachedtowindow ()</strong></p></p><p><p><strong>{</strong></p></p><p><p><strong>TODO auto-generated Method Stub</strong></p></p><p><p><strong></strong> <strong>this.getwindow (). setType (WindowManager.LayoutParams.TYPE_KEYGUARD); </strong></p></p><p><p><strong>Super.onattachedtowindow ();</strong></p></p><p><p><strong>}  </strong><strong>   </strong><strong>   </strong></p></p><p><p><strong>Add permission to prohibit the home button</strong></p></p><p><p><strong><uses-permission android:name= "android.permission.DISABLE_KEYGUARD" ></uses-permission></strong></p></p><p><p>Android Custom Keys</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.