主页按钮禁用(KEYGUARD_DIALOG)IllegalArgumentException

时间:2017-05-05 00:59:54

标签: java android android-studio illegalargumentexception

我试图制作自定义锁定屏幕,我需要禁用主页按钮操作。我的minSdkVersion:17,targetSdkVersion 25

我的新onAttachedToWindow():

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

我的onCreate():

@Override
protected void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);

}

错误日志:

java.lang.IllegalArgumentException: Window type can not be changed after the window is added.

我尝试使用onKeyMethod它没有帮助:

public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_HOME)) {
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }

是否有任何方法没有将活动显示为启动器

        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.HOME" />
        <category android:name="android.intent.category.DEFAULT" />

0 个答案:

没有答案