我想在Android 3.1中隱藏狀態欄。 當用戶觸摸屏幕時,狀態欄將會顯示,2秒後將自動隱藏。無法隱藏狀態欄?
這裏我的代碼:
private static ViewFlipper flipper = null;
private static ImageView ivScreenSnapshot = null;
public static AbsoluteLayout managerField = null;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
managerField = new AbsoluteLayout(this);
flipper = new ViewFlipper(this)
{
@Override
public boolean onTouchEvent(MotionEvent event)
{
flipper.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
Thread t = new Thread()
{
public void run()
{
try {
sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Global.handler.post(new Runnable()
{
public void run()
{
flipper.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
}
});
}
};
t.start();
return super.onTouchEvent(event);
}
};
ivScreenSnapshot = new ImageView(this);
flipper.addView(managerField);
flipper.addView(ivScreenSnapshot);
setContentView(flipper);
flipper.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
}
它不工作,狀態欄始終可見。 有什麼建議嗎?謝謝!
謝謝大家, 我的代碼不工作,因爲我已經在manfest文件中聲明瞭android:minSdkVersion = 8。 現在,我編輯android:minSdkVersion = 12,它工作正常。 – Levanphong7887