Android home screen button

2011-05-31  来源:本站原创  分类:Mobile  人气:342 

In the activity, add the following code can shield home

@Override
        public boolean onKeyDown(int keyCode, KeyEvent event)
        {
                // TODO Auto-generated method stub
                //  Press the return button on the keyboard 

                if (keyCode == KeyEvent.KEYCODE_HOME)
                {
                        Log.i("TAG","home");
                        System.exit(0);
                        return true;
                }
                else
                        return super.onKeyDown(keyCode, event);

        }

Premise is to rewrite onAttachedToWindow () this method.

@Override
        public void onAttachedToWindow()
        {
                this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
                super.onAttachedToWindow();
        }

Because the android system key PhoneWindowManager own home to do a deal, would not return to the upper application. View Source Code:

\ Frameworks \ policies \ base \ phone \ com \ android \ internal \ policy \ impl \ PhoneWindowManager.java 1089 lines

if (code == KeyEvent.KEYCODE_HOME) {
            // If a system window has focus, then it doesn't make sense
            // right now to interact with applications.
            WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
            if (attrs != null) {
                final int type = attrs.type;
                if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
                        || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
                    // the "app" is keyguard, so give it the key
                    return false;
                }
                final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
                for (int i=0; i<typeCount; i++) {
                    if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
                        // don't do anything, but also don't pass it to the app
                        return true;
                    }
                }
            }

Note, activity in the rewrite onAttachedToWindow () method requires api 5 or more

Table attached to API Level

Android 2.3 - API Level 9

2.2 - 8

2.1 - 7

2 .. 0.1 - 6

2.0 - 5

1.6 - 4

1.5 -3

1.1 - 2

相关文章
  • Android home screen button 2011-05-31

    In the activity, add the following code can shield home @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub // Press the return button on the keyboard if (keyCode == KeyEvent.KEYCODE_HOME) { Log.i("TAG

  • Android horizontal screen portrait screen setting skills 2010-08-26

    Android horizontal screen portrait screen setting skills getWindow (). setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); / / set to full screen mode setRequestedOrientation (ActivityInfo.SCREEN_ORIENTA

  • Android 控件(button)对齐方法实现详解 2014-05-16

    horizontal是让所有的子元素按水平方向从左到右排列,vertical是让所有的子元素按竖直方向从上到下排列,下面为大家介绍下控件(button)的对齐方法 1,android:orientation 布局方向.horizontal是让所有的子元素按水平方向从左到右排列, vertical是让所有的子元素按竖直方向从上到下排列. 2,android:gravity 与 android:layout_gravity的区别android:gravity是指定本元素的子元素相对它的对齐方式. a

  • Android中的Button自定义点击效果实例代码 2014-12-25

    Android中的Button自定义点击效果实例代码,需要的朋友可以参考一下 方法一 1.放在drawable下的selector.xml文件 <android="http://schemas.android.com/apk/res/Android"> android:drawable="@drawable/temp2" /> 2.布局文件main.xml 复制代码 代码如下: <http://schemas.android.com/apk/

  • Android Application screen control Androidscreencast achieve 2010-12-30

    The work of a small tool used in sun drying out: Androidscreencastcase one for Windows / Linux / MacOS platform to control any android device, USB connection can be achieved through mouse and keyboard to control your android. Official Description: De

  • Android shielding Home button 2011-05-23

    public void onAttachedToWindow() { this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); super.onAttachedToWindow(); } Add this code in the activity can mask home, as to why, because the android system itself on the power button and hom

  • Growth set of learning android horizontal screen UI 2010-04-29

    In the development, some procedures are only screen play, so when placing phone erected to keep the interface surface remains horizontal screen. In AndroidManifest.xml which configuration click on it. Join the line android: screenOrientation = "lands

  • Android Touch Screen with tslib calibrated to achieve 2010-05-10

    1, touch screen calibration method mainly uses the following general formula to achieve touch screen calibration, which XL, YL is the screen coordinates, XT, YT is the touch screen coordinates, XL = XT * A + YT * B + C; YL = XT * D + YT * E + F; form

  • android lock screen realization of ideas 2010-05-14

    Before the thought process to achieve a lock screen, has no hands, try a bit today. First of all, have to shut down the screen to hear the broadcast system, the radio what is it? Do not know ah. How to do that? Search Bai! Search, can be found, but I

  • Android anyway screen switching method 2010-06-30

    Android if they had to switch on the screen solution Reprinted from :http://rayleung.javaeye.com/blog/426972 In the development of the game, some games can only play in landscape mode of the , Therefore, when placing phone erected to keep the game sc

  • android summary screen anyway 2010-08-06

    Android screen anyway to solve the problem should be on two: 1. Layout problem; 2. Re-loading problem. 1. Layout: If you do not want the software to switch between horizontal and vertical screen, the easiest way is to be found in the project AndroidM

  • Android --- ListView + Select button (switch) 2010-09-03

    In the android system, ListView usage a bit more complicated, there are several ways to configure Adpater, such as ArrayAdapter, SimpleAdapter so. Check some relevant examples online, many are using ListActivity, then use the Adapter to display the l

  • android startup screen Splash (method 2) 2010-09-07

    On an article that the first method. 1, with two Activity, the program starts when the first load Activity, and then triggered by the tick N seconds startActivity another one Activity. 2, using a Activity, you can use View.gone () this method. Remove

  • Android boot screen changes 2010-09-26

    Android system boot animation consists of two parts: Boot display ANDROID text; ANDROID light animation. The article said that animation is the first boot, start the following text! 1. Making the current screen pixel of the image (simulator defaults

  • Android - turn screen to prohibit call onCreate () (reprint) 2010-10-19

    Automatically rotates the screen if they had, each time re-call onCreate, and then load the data if they are slightly larger when they need to wait, in fact, onCreate this step is not necessary to access some information, you can avoid this by settin

  • android achieve Draggable Button 2010-11-17

    Achieve results, Buttton drag around within the screen, but not out of the screen, the code is as follows: public class DraftTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setCo

  • android summary screen anyway (to) 2010-11-30

    Android if they had screen problems should be two: one. Layout problem; II. Reload problem. 1. Layout problem: If you do not want the software to switch between horizontal and vertical screen, the easiest way is to be found in the project AndroidMani

  • Android - Click the button on the dialog box does not close the dialog box 2010-12-04

    Sometimes I may need to click the button did some testing, but do not want to close the second dialog box (click on any button on the system default is to close the dialog), treatment methods are as follows: In the click event to add the following co

  • Android点击Button实现功能的几种方法总结 2014-05-26

    当Button有多个或者Button的使用次数很多时,我们需要采用绑定监听器的做法,其实,绑定监听器也有几种方法,不过,我在这里就不一一列举了,毕竟那些方法在实际的应用中也不常见 Android中Button控件应该算作是比较简单的控件,然而,它的使用频率却是非常的高,今天,我在这里总结了三种常用的点击Button实现其功能的方法. 1.很多时候,我们在用到Button控件时,往往都是"一次性"使用,这时,为了方便起见,我们一般采用的是匿名内部类的方法,形如这样: button1.se

  • More about keeping Android's screen awake 2013-06-19

    In my previous post, I discussed the pros and cons of the various means of keeping the screen alive in Android, focusing mainly on the need for sandbox permissions in your application'sAndroidManifest.xmlfile. In this post, I'd like to further elabor