仿IOS透明通知欄(僅支援4.4以上版本)

來源:互聯網
上載者:User

標籤:透明通知欄

從4.4開始,Google為Android增加了透明狀態列和導覽列的功能,只需要加入少量代碼就可以實現。


在Activity的布局檔案父View中添加屬性:android:fitsSystemWindows="true"android:clipToPadding="true"即可。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:custom="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:fitsSystemWindows="true"    android:clipToPadding="true"    android:background="#ffe5ff3e">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical">        <TextView            android:layout_width="match_parent"            android:layout_height="match_parent"            android:padding="16dp"            android:textSize="18sp"            android:text="@string/mytext" />    </LinearLayout></ScrollView>

如果不想要ActionBar,可以在AndroidManifest.xml或者Activity中去除,就得到效果。但是,透明通知欄只支援4.4以上的系統,在4.4以下還是會顯示預設的通知欄。


如果希望修改通知欄顏色,可以參考Github大牛的Demo:

https://github.com/jgilfelt/SystemBarTint

其中的library只有一個SystemBarTintManager類,可以拷貝到自己的工程中使用,這樣就不用依賴那個library了。

仿IOS透明通知欄(僅支援4.4以上版本)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.