首页 > 代码库 > Android全透明状态栏效果(我的手机安卓版本是4.2.2)

Android全透明状态栏效果(我的手机安卓版本是4.2.2)

 //ALT+Enter, 自行引入相应的包,
 1 public class MainActivity extends Activity {  
 2       
 3     @SuppressLint("InlinedApi")  
 4     @Override  
 5     protected void onCreate(Bundle savedInstanceState) {  
 6         super.onCreate(savedInstanceState);  
 7         getWindow().requestFeature(Window.FEATURE_NO_TITLE);  
 8         if(VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {  
 9             Window window = getWindow();  
10             window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS  
11                     | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);  
12             window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN  
13                             | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  
14                             | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);  
15             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);  
16             window.setStatusBarColor(Color.TRANSPARENT);  
17             window.setNavigationBarColor(Color.TRANSPARENT);  
18         }  
19   
20         setContentView(R.layout.activity_main);  
21     }  
22   
23 }  

 

Android全透明状态栏效果(我的手机安卓版本是4.2.2)