android開發(31) 讓 actionbar 透明

來源:互聯網
上載者:User

標籤:android   style   blog   http   color   io   使用   ar   2014   

我需要一個 透明的actionbar ,找到如下方法實現:

1. 首先,設定ActionBar 浮動到主介面上來。

2. 然後,設定ActionBar的背景色,透明或者半透明。

 

那麼如何?這兩步呢?

第一步:

代碼實現: 在oncreate中:getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

使用theme 在style中實現: <item name="android:windowActionBarOverlay">true</item> 

第二步:

代碼實現:

ActionBar actionBar = getActionBar();actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33000000")));//google的actionbar是分為上下兩欄顯示的,上面的代碼只能設定頂部actionbar的背景色,//為了讓下面的背景色一致,還需要添加一行代碼:actionBar.setSplitBackgroundDrawable(new ColorDrawable(Color.parseColor("#33000000")));        

使用theme 在style中實現:

<resources>    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">        <item name="android:windowActionBarOverlay">true</item>         <!-- 讓actionbar漂浮 -->        <item name="android:actionBarStyle">@style/my_actionbar_style</item>    </style>    <style name="my_actionbar_style" parent="@android:style/Widget.Holo.Light.ActionBar">         <!-- 設定actionbar 背景色 透明 -->        <item name="android:background">#33000000</item>        <item name="android:backgroundStacked">#346c36</item>        <item name="android:backgroundSplit">#33000000</item>    </style></resources>

android開發(31) 讓 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.