我正在尝试实现全屏活动,也称为沉浸式模式。在 android 文档中,我读到:“启用沉浸式全屏模式后,您的 Activity 将继续接收所有触摸事件。用户可以沿着系统栏通常出现的区域向内滑动来显示系统栏。” 我在带有模拟器的android studio上尝试了很多示例,并且使用我自己的代码我可以进入沉浸式全屏模式,但我无法退出。这很简单,只需向内滑动手势即可重新显示操作栏,但我不能。我注意到第一次进入沉浸式模式时,以及在我关闭并重新打开虚拟设备后,riminder 气泡也没有显示。这是代码,gradle(使用的avd是lollipop api level 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);
}
}
build.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'
}