隐藏特定时间的状态栏和标题栏
Hiding the status bar and title bar for a specific time
我想在特定时间在同一布局中隐藏状态栏和标题栏。像 2 或 3 秒。为此,我尝试了 Timer
,据我所知,功能请求( requestFeature()
) 必须在 SetContentView
和 Super.OnCreate
之前调用。所以,我写了这段代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Hiding Title bar of this activity screen //
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
// Making this activity, full screen //
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
});
}
}, 1000, 5000);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
但它伴随着以下错误:
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
我认为 Timer 是错误的原因。因为,当我在没有 Timer
的情况下调用 requestFeature() 时,应用程序运行时没有显示任何错误或崩溃。
Is there any way to hide status and title bar for a specific time in the same layout? (Not Intent)
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Hiding Title bar of this activity screen //
getSupportActionBar().hide();
// Making this activity, full screen //
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
});
}
}, 1000, 5000);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
将 getWindow().requestFeature(Window.FEATURE_NO_TITLE);
替换为 getSupportActionBar().hide();
。
使用下面的代码
全屏
// Full Screen call using DecorView
private void setFullScreen() {
getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);
}
从全屏移除
private void removeFromFullScreen() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
现在在你的 OnCreate()
@Override
protected void onCreate(Bundle savedInstanceState) {
final android.os.CountDownTimer Count = new android.os.CountDownTimer(5000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
if (millisUntilFinished/1000 == 2) {
setFFullScreen();
}
Log.e("TAG",millisUntilFinished/1000+"");
}
@Override
public void onFinish() {
removeFromFullScreen();
}
};
Count.start();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
我想在特定时间在同一布局中隐藏状态栏和标题栏。像 2 或 3 秒。为此,我尝试了 Timer
,据我所知,功能请求( requestFeature()
) 必须在 SetContentView
和 Super.OnCreate
之前调用。所以,我写了这段代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Hiding Title bar of this activity screen //
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
// Making this activity, full screen //
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
});
}
}, 1000, 5000);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
但它伴随着以下错误:
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
我认为 Timer 是错误的原因。因为,当我在没有 Timer
的情况下调用 requestFeature() 时,应用程序运行时没有显示任何错误或崩溃。
Is there any way to hide status and title bar for a specific time in the same layout? (Not Intent)
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Hiding Title bar of this activity screen //
getSupportActionBar().hide();
// Making this activity, full screen //
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
});
}
}, 1000, 5000);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
将 getWindow().requestFeature(Window.FEATURE_NO_TITLE);
替换为 getSupportActionBar().hide();
。
使用下面的代码
全屏
// Full Screen call using DecorView
private void setFullScreen() {
getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);
}
从全屏移除
private void removeFromFullScreen() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
现在在你的 OnCreate()
@Override
protected void onCreate(Bundle savedInstanceState) {
final android.os.CountDownTimer Count = new android.os.CountDownTimer(5000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
if (millisUntilFinished/1000 == 2) {
setFFullScreen();
}
Log.e("TAG",millisUntilFinished/1000+"");
}
@Override
public void onFinish() {
removeFromFullScreen();
}
};
Count.start();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);