直接在setContentView(R.layout.activity_main);以前添加如下代碼android
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION //這裏刪除的話 能夠解決華爲虛擬按鍵的覆蓋
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT);//這裏刪除的話
}
實現效果以下面試
第二種實現方法:在styles.xml中添加透明小程序
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--<item name="colorPrimary">@color/colorPrimary</item>-->
<!--<item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
<!--<item name="colorAccent">@color/colorAccent</item>-->
<item name="android:windowTranslucentStatus" tools:ignore="NewApi">true</item>
</style>
<style name="AppTheme.Main." parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowTranslucentStatus" tools:ignore="NewApi">true</item>
</style>
性能優化
在建立一個文件夾values-19和文件styles.xml架構
在文件裏添加解決 狀態欄和佈局重疊的樣式app
<resources>
<style name="AppTheme.Main" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
在根佈局裏添加佈局
android:fitsSystemWindows="true"
性能
想學習更多Android知識,請加入Android技術開發企鵝交流 7520 16839學習
進羣與大牛們一塊兒討論,還可獲取Android高級架構資料、源碼、筆記、視頻優化
包括高級UI、Gradle、RxJava、小程序、Hybrid、移動架構、React Native、性能優化等全面的Android高級實踐技術講解性能優化架構思惟導圖,和BATJ面試題及答案!
羣裏免費分享給有須要的朋友,但願可以幫助一些在這個行業發展迷茫的,或者想系統深刻提高以及困於瓶頸的朋友,在網上博客論壇等地方少花些時間找資料,把有限的時間,真正花在學習上,因此我在這免費分享一些架構資料及給你們。但願在這些資料中都有你須要的內容。