[英]Android: how to hide title bar on button click
App crashing when using requestWindowFeature(Window.FEATURE_NO_TITLE);
使用
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 我想使其全屏显示(同时隐藏状态和标题栏)
Please note: this is also to be called to fragments 请注意:这也称为片段
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" 机器人:主题= “@安卓风格/ Theme.NoTitleBar.Fullscreen”
// Hide status bar // 隐藏状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 。getWindow()addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Show status bar //显示状态栏
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 。getWindow()clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.