2011-12-24 31 views
13

我正在製作自定義鎖定屏幕。全屏透明活動(無標題和狀態欄)不起作用....爲什麼?

鎖定屏幕是我在屏幕關閉時啓動的一項活動。

但是,我不能讓這個活動成爲全屏透明的&。

狀態欄不斷顯示。

這就是我在清單做:

<activity android:name=".activities.LockScreenActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/> 

我也加入在activit的onCreate這些額外:

requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.lock_screen); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 

但它似乎無法工作:|

爲什麼?

回答

40

從onCreate()中刪除代碼。在Manifestfile中使用它。

android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" 

否則根據您的要求創建主題。

+1

不工作,我的朋友。是如何從<活動的Android不同:名稱=「。activities.LockScreenActivity」android:theme =「@ android:style/Theme.Translucent.NoTitleBar.Fullscreen」/>? – dor506 2011-12-24 09:18:23

+0

更好使用半透明和nototlebar。 – 2011-12-24 09:39:57

+0

林不知道我跟着你。正如我所說,我寫在清單android:theme =「@ android:style/Theme.Translucent.NoTitleBar.Fullscreen」,你告訴我在onCreate中使用這個:setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); 。糾正我,如果即時通訊錯誤,但它不是一回事嗎? – dor506 2011-12-24 09:51:02

3

你需要的setContentView之前設置的標誌,它應該工作得很好,那麼

requestWindowFeature(Window.FEATURE_NO_TITLE); 
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 

setContentView(R.layout.lock_screen); 
0

這裏是它link(隱藏在Android 4.1及更高的狀態欄)。

View decorView = getWindow().getDecorView(); 
// Hide the status bar. 
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; 
decorView.setSystemUiVisibility(uiOptions); 
// Remember that you should never show the action bar if the 
// status bar is hidden, so hide that too if necessary. 
ActionBar actionBar = getActionBar(); 
actionBar.hide(); 

隱藏在Android 4.0和更低的狀態欄:

<application 
    ... 
    android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" > 
    ... 
</application> 

@Override 
 
    protected void onCreate(Bundle savedInstanceState) { 
 
     super.onCreate(savedInstanceState); 
 
     // If the Android version is lower than Jellybean, use this call to hide 
 
     // the status bar. 
 
     if (Build.VERSION.SDK_INT < 16) { 
 
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
 
        WindowManager.LayoutParams.FLAG_FULLSCREEN); 
 
     } 
 
     setContentView(R.layout.activity_main); 
 
    }