【问题标题】:Can I disable home button On Android我可以在Android上禁用主页按钮吗
【发布时间】:2017-06-14 11:59:22
【问题描述】:

我无法禁用主页按钮,在 android 中它旁边是哪个我试过这段代码但不起作用

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

你有解决这个问题的想法吗? 或者我可以永久隐藏导航栏吗?

【问题讨论】:

  • 你想永远隐藏导航栏!?你为什么要做这样的事情?您可以在全屏时全屏并隐藏它
  • 您不能在 Android 中禁用或完全隐藏导航栏。但是您可以将您的应用设置为一种启动器,例如在这篇文章中:stackoverflow.com/a/27120660/5508719
  • 请注意,不允许您的用户退出您的应用可能会让他们对您有点生气。
  • 应该没有办法。
  • @JulianSchmuckli 谢谢你拯救了我的一天

标签: java android xml


【解决方案1】:

我可以永久隐藏导航栏吗?

不,系统不允许您这样做。但是您可以阻止应用程序退出。 在 onPause() 方法中执行以下操作。

 @Override
    protected void onPause() {
        super.onPause();
        ActivityManager activityManager = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);
        activityManager.moveTaskToFront(getTaskId(), 0);
    }

您需要以下权限

<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.REORDER_TASKS" />

【讨论】:

  • 谢谢,但不起作用。我需要任何许可吗?
  • 这是一件好事,但只适用于方形按钮,主页按钮不起作用
【解决方案2】:

我找到了。 我从这里参加了 how to disable home button in android? 并添加了原来存在的一行 LAUNCHER 行如下:

<activity android:name=".MainActivity"
        android:clearTaskOnLaunch="true"
        android:excludeFromRecents="true"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:stateNotNeeded="true" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

        </intent-filter>
    </activity>

【讨论】:

    猜你喜欢
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 2012-01-09
    相关资源
    最近更新 更多