Android Custom Keys
Last Update:2016-01-07
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>