ActionBar開啟Overlay Mode(覆蓋模式),actionbaroverlay

來源:互聯網
上載者:User

ActionBar開啟Overlay Mode(覆蓋模式),actionbaroverlay

以下內容參考自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的背景為透明即可。

效果如下。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.