屏幕锁定后,防止隐藏状态栏重新出现

时间:2012-03-14 12:30:36

标签: android fullscreen statusbar screen-lock

我想在我的应用程序中隐藏状态栏以使其全屏显示,所以我使用此示例Hide Notification bar - 它工作正常。但是,如果我锁定屏幕然后解锁它,状态栏会出现,如何解决这个问题?

5 个答案:

答案 0 :(得分:1)

要隐藏Android状态栏和应用程序标题栏,请将以下内容添加到清单文件中:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

示例:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="de.vogella.android.temperature"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Convert"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="9" />

</manifest>

<强>已更新

从锁屏返回后,还尝试将此代码放入相关活动中:

public class FullScreen extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);
    }
}

答案 1 :(得分:1)

如果安全性不是问题,您可以在应用运行时禁用锁定屏幕。将以下行添加到清单:

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

在您的活动中,您可以执行以下操作:

public class MyActivity extends Activity {
    private KeyguardLock lock;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Disable lock screen.
        KeyguardManager keyGuardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
        lock = keyGuardManager.newKeyguardLock("MyActivity");
        lock.disableKeyguard();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // Reenable the lock screen again.
        lock.reenableKeyguard();
    }
}

答案 2 :(得分:0)

onCreate()

之前setContentView()使用此代码
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

答案 3 :(得分:0)

仅将其添加到样式

 <style name="AppTheme" parent="Theme.Design.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowFullscreen">true</item>
</style>

答案 4 :(得分:-2)

将此代码写入应用程序标签中的application.xml文件中,如下所示:

<application  android:name="application package"
            android:label="application name" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">