Android:如何在单击按钮时隐藏标题栏 [英] Android: how to hide title bar on button click
问题描述
使用requestWindowFeature(Window.FEATURE_NO_TITLE);
使用按钮使其全屏显示时,当尝试隐藏标题栏时,应用程序崩溃
When using the button to make it full screen which when tries to hide the Title bar the app crashes
static int vari = 0;
public void fsc(){
ib = (ImageButton) findViewById(R.id.fulls);
ib.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Full-Screen", Toast.LENGTH_LONG).show();
if(vari == 0)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
vari = 1;
}
});
我想按按钮使其全屏显示(同时隐藏状态栏和标题栏)
I wanted to make it full screen (hiding both status and title bar) on the button press
请注意:这也称为片段
推荐答案
检查清单中是否设置了全屏主题?
Check if you have the fullscreen theme set in the manifest?
//如果不将其添加到清单中
//if not add this in your manifest
android:theme ="@ android:style/Theme.NoTitleBar.Fullscreen"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
//隐藏状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
//显示状态栏
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
这篇关于Android:如何在单击按钮时隐藏标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!