Android沉浸式頂部實現(xiàn)代碼及效果
研究了下這個,記錄下代碼。
主頁面代碼:activity_main.xml
<?xml version='1.0' encoding='utf-8'?><android.support.constraint.ConstraintLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.MainActivity'> <TextView android:layout_width='match_parent' android:layout_height='70dp' android:text='Hello World!' android:gravity='center' android:background='@color/colorAccent' app:layout_constraintLeft_toLeftOf='parent' app:layout_constraintRight_toRightOf='parent' app:layout_constraintTop_toTopOf='parent' /> <!-- android:fitsSystemWindows='true' android:clipToPadding='true'--></android.support.constraint.ConstraintLayout>
添加三個文件:三份 style 文件,即默認(rèn)的values(不設(shè)置狀態(tài)欄透明)、values-v19、values-v21(解決半透明遮罩問題)。
values 下 style.xml
<style name='TranslucentTheme' parent='AppTheme'> <!--在Android 4.4之前的版本上運行,直接跟隨系統(tǒng)主題--> </style>
values-v19 下 style.xml
<?xml version='1.0' encoding='utf-8'?><resources> <style name='TranslucentTheme' parent='Theme.AppCompat.Light.NoActionBar'> <item name='android:windowTranslucentStatus'>true</item> <item name='android:windowTranslucentNavigation'>true</item> </style></resources>
values-v21 下 style.xml
<?xml version='1.0' encoding='utf-8'?><resources> <style name='TranslucentTheme' parent='Theme.AppCompat.Light.NoActionBar'> <item name='android:windowTranslucentStatus'>false</item> <item name='android:windowTranslucentNavigation'>true</item> <item name='android:statusBarColor'>@android:color/transparent</item> </style></resources>
這里需要在:AndroidMainfest.xml 里添加樣式。
<?xml version='1.0' encoding='utf-8'?><manifest xmlns:android='http://schemas.android.com/apk/res/android' package='controller.hzl.com.dingbu2'> <application android:allowBackup='true' android:icon='@mipmap/ic_launcher' android:label='@string/app_name' android:roundIcon='@mipmap/ic_launcher_round' android:supportsRtl='true' android:theme='@style/AppTheme'> <activity android:name='.MainActivity' android:theme='@style/TranslucentTheme' > <intent-filter><action android:name='android.intent.action.MAIN' /><category android:name='android.intent.category.LAUNCHER' /> </intent-filter> </activity> </application></manifest>
主Acitivity沒有修改。
效果圖:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Python自動化之定位方法大殺器xpath2. python調(diào)用百度API實現(xiàn)人臉識別3. 如何基于Python和Flask編寫Prometheus監(jiān)控4. Python Selenium破解滑塊驗證碼最新版(GEETEST95%以上通過率)5. python 寫一個文件分發(fā)小程序6. 用python對oracle進(jìn)行簡單性能測試7. Python 利用flask搭建一個共享服務(wù)器的步驟8. Python QT組件庫qtwidgets的使用9. Vue3中使用this的詳細(xì)教程10. Python中Anaconda3 安裝gdal庫的方法
