Android主页按钮禁用错误

时间:2016-06-23 18:04:06

标签: java android android-button android-homebutton kiosk-mode

我正在开发一些Android应用程序。在应用程序中我想禁用主页按钮 所以我试图覆盖onAttachedToWindow方法,但问题是我在启动应用程序时遇到错误。

代码:

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

错误:

  

java.lang.IllegalArgumentException:添加窗口后无法更改窗口类型。                                                                                        在android.os.Parcel.readException(Parcel.java:1603)                                                                                        在android.os.Parcel.readException(Parcel.java:1552)                                                                                        在android.view.IWindowSession $ Stub $ Proxy.relayout(IWindowSession.java:912)                                                                                        在android.view.ViewRootImpl.relayoutWindow(ViewRootImpl.java:5415)                                                                                        在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1581)                                                                                        在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)                                                                                        在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6013)                                                                                        在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:858)                                                                                        在android.view.Choreographer.doCallbacks(Choreographer.java:670)                                                                                        在android.view.Choreographer.doFrame(Choreographer.java:606)                                                                                        在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:844)                                                                                        在android.os.Handler.handleCallback(Handler.java:739)                                                                                        在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                        在android.os.Looper.loop(Looper.java:148)                                                                                        在android.app.ActivityThread.main(ActivityThread.java:5417)                                                                                        at java.lang.reflect.Method.invoke(Native Method)                                                                                        在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                                        在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

任何人都有想法,这段代码的错误是什么?

2 个答案:

答案 0 :(得分:1)

我找到了问题的答案。在android Lolipop中有startLockTask()函数。这将固定你的任务。大家好。

答案 1 :(得分:0)

正如我在其他问题中所提到的,您无法禁用或覆盖,甚至无法检测主页按钮。 只能在setContentView()之前设置窗口类型。