Android全屏 - 沉浸式模式活动向内滑动不起作用

时间:2016-03-25 08:32:46

标签: android fullscreen swipe-gesture android-immersive

我试图用全屏幕实现一项活动,称为沉浸式模式。在Android文档中,我读到:"启用沉浸式全屏模式后,您的活动将继续接收所有触摸事件。用户可以通过沿系统条通常出现的区域向内滑动来显示系统条。" 我在android studio上用仿真器尝试了很多例子,而且我自己的代码也可以进入沉浸式全屏模式,但是我无法退出。这将是简单的,只是向内轻扫手势重新显示动作栏,但我不能。我注意到,在我关闭并重新打开虚拟设备之后,第一次进入沉浸式模式时也没有显示出破坏性气泡。 这是代码,gradle(使用的avd是棒棒糖api等级21):

package net.missionaridellavia.gospelway.activity;

import android.os.Bundle;
import android.view.View;

import net.missionaridellavia.gospelway.R;


public class MainActivity extends AbstractCustomActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.container);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);}
}
}

package net.missionaridellavia.gospelway.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;

import net.missionaridellavia.gospelway.R;
import net.missionaridellavia.gospelway.service.DebuggerActivity;

public class AbstractCustomActivity extends DebuggerActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //
        final ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
            case R.id.action_settings:
                Intent intentSettings = new Intent(getApplicationContext(),
                        SettingsActivity.class);
                startActivity(intentSettings);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

buil.gradle是:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "net.missionaridellavia.gospelway"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:support-v4:22.2.1'
}

0 个答案:

没有答案