我知道可以在活动清单中按标记全屏显示应用android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
是否可以通过编程方式从应用内切换到全屏模式?
答案 0 :(得分:60)
添加两行...
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
答案 1 :(得分:10)
您可以创建新样式并添加
<item name="android:windowFullscreen">true</item>
或者您可以通过编程方式执行此操作:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
答案 2 :(得分:8)
在setContentView:
之前在Activity onCreate中添加它@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
并在AndroidManifest.xml文件中:
<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
答案 3 :(得分:1)
如果您需要全屏沉浸模式(用于游戏、画廊等),这里是我使用和推荐的解决方案。
最有效的方法是仅在需要时才设置 SystemUIVisibility:
公共类 BaseActivity 扩展 Activity {
@SuppressLint("InlinedApi")
private static final int UI_OPTIONS = View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Step 1
hideSystemUI();
// Step 2
getWindow().getDecorView()
.setOnSystemUiVisibilityChangeListener(new View
.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
hideSystemUI();
}
}
});
}
private void hideSystemUI() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) actionBar.hide();
getWindow().getDecorView().setSystemUiVisibility(UI_OPTIONS);
}
}
答案 4 :(得分:0)
试试这个,
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
或
<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
答案 5 :(得分:0)
在onCreate()方法中写
requestWindowFeature(Window.FEATURE_NO_TITLE); 。this.getWindow()setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);