ActionBar開啟Overlay Mode(覆蓋模式)


以下內容參考自Android官網http://developer.android.com/training/basics/actionbar/overlaying.html#EnableOverlay

 

直接調用ActionBar的hide()和show()方法,會造成Activity重新計算和重新繪制布局的新的大小。為了避免這種情況,需要使用Overlay Mode。

在3.0及以上,啟用覆蓋模式只需要在自定義的Theme中將android:windowActionBarOverlay性質設置為true。例如:

<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme" parent="@android:style/Theme.Holo">
        <item name="android:windowActionBarOverlay">true</item>
    </style>
</resources>

在3.0以下的話:

<resources>     <!-- the theme applied to the application or activity -->     <style name="CustomActionBarTheme"            parent="@android:style/Theme.AppCompat">         <!-- Support library compatibility -->         <item name="windowActionBarOverlay">true</item>     </style>
</resources>

別忘了去Manifest.xml文件去設置Theme。

如果想在覆蓋模式下,依然讓布局顯示在ActionBar的下方,則在布局文件的父布局下設置paddingTop屬性值:

3.0以上版本:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="?android:attr/actionBarSize"> ... </RelativeLayout>

3.0以下版本:

<!-- Support library compatibility -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="?attr/actionBarSize"> ... </RelativeLayout>

 

提示:如果想讓ActionBar顯示在布局的前面,也可以設置ActionBar的背景為透明即可。

效果如下。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM