日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

android fitsSystemWindows的使用

發布時間:2024/4/15 59 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android fitsSystemWindows的使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天,簡單講講android 

fitsSystemWindows的使用。


Android使用fitsSystemWindows屬性實現--狀態欄【status_bar】各版本適配方案


fitSystemWindows屬性:

????官方描述:

????????Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.

????簡單描述:

?????這個一個boolean值的內部屬性,讓view可以根據系統窗口(如status bar)來調整自己的布局,如果值為true,就會調整view的paingding屬性來給system windows留出空間....

實際效果:

?????當status bar為透明或半透明時(4.4以上),系統會設置view的paddingTop值為一個適合的值(status bar的高度)讓view的內容不被上拉到狀態欄,當在不占據status bar的情況下(4.4以下)會設置paddingTop值為0(因為沒有占據status bar所以不用留出空間)。


  • 1.fitsSystemWindow 默認是true,就是組件都在屏幕內,但是不包括statusBar。設置成false后,整個屏幕都可以放置組件,沒有statusBar和window之分。

  • 2.android:fitsSystemWindows=“true”在布局中占有最高權限,如果明確設置為true,style設置fits為false是無效的;同理,只在布局中設置fits而沒有設置style也是無效的。

平時使用中只需要設置style即可。效果就是整個圖片鋪滿手機界面。


<style name="NoStatusStyle" parent="AppTheme"> <item name="android:windowTranslucentStatus">true</item> <!--狀態欄為透明,如果設置為false,則沒有黑色條蓋住,見下圖對比--> <item name="android:windowTranslucentNavigation">true</item> <!--導航欄為透明--> <item name="android:statusBarColor">@android:color/transparent</item> </style>



(注:在布局中都是android:fitsSystemWindows="false")


3.有時候會出現statusbar把界面蓋住的情況,一般都是fits設置的有問題,或是在布局(android:fitsSystemWindows="false"),或是在style中fits設置為了false(<item name="android:fitsSystemWindows">false</item>),但是statusbar沒有設置為透明,造成了界面被遮蓋的現象。解決辦法就是上面的代碼塊中的代碼。(要明白自己的意圖再去修改)


android fitsSystemWindows的使用就講完了。


就這么簡單。

總結

以上是生活随笔為你收集整理的android fitsSystemWindows的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。