2011-12-24 63 views
13

Tôi đang tạo màn hình khóa tùy chỉnh.Hoạt động trong suốt toàn màn hình (không có tiêu đề & thanh trạng thái) không hoạt động .... tại sao?

Màn hình khóa là một hoạt động mà tôi khởi chạy vào thời điểm màn hình tắt.

Tuy nhiên, tôi không thể làm cho hoạt động trở nên trong suốt cả & toàn màn hình.

Thanh trạng thái tiếp tục hiển thị.

Đây là những gì tôi làm trong manifest:

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

Tôi cũng đang thêm các tính năng bổ sung trong onCreate activit của:

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

Nhưng nó dường như không thể làm việc: |

lý do tại sao?

Trả lời

40

xóa mã khỏi onCreate(). sử dụng điều này trong Manifestfile.

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

nếu không tạo chủ đề theo yêu cầu của bạn.

+1

không hoạt động bạn bè của tôi .. thế nào là khác nhau từ ? – dor506

+0

tốt hơn để sử dụng mờ và nototlebar. –

+0

Tôi không chắc chắn tôi sẽ theo bạn. Như tôi đã nói, tôi đã viết trong tệp kê khai android: theme = "@ android: style/Theme.Translucent.NoTitleBar.Fullscreen" và bạn đã nói với tôi để sử dụng điều này trong onCreate: setTheme (android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); . Đúng nếu tôi sai, nhưng không phải là điều tương tự sao? – dor506

3

bạn cần thiết lập cờ trước setContentView, nó sẽ làm việc tốt sau đó

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

setContentView(R.layout.lock_screen); 
0

Đây là nó link (ẩn thanh trạng thái trên Android 4.1 và cao hơn).

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(); 

ẩn thanh trạng thái trên Android 4.0 và dưới:

<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); 
 
    }

Các vấn đề liên quan