Android沉浸式頂部實(shí)現(xiàn)代碼及效果
研究了下這個(gè),記錄下代碼。
主頁(yè)面代碼: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>
添加三個(gè)文件:三份 style 文件,即默認(rèn)的values(不設(shè)置狀態(tài)欄透明)、values-v19、values-v21(解決半透明遮罩問(wèn)題)。
values 下 style.xml
<style name="TranslucentTheme" parent="AppTheme">
<!--在Android 4.4之前的版本上運(yùn)行,直接跟隨系統(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沒(méi)有修改。
效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)沉浸式狀態(tài)欄功能
- Android隱藏和沉浸式虛擬按鍵NavigationBar的實(shí)現(xiàn)方法
- Android編程中沉浸式狀態(tài)欄的三種實(shí)現(xiàn)方式詳解
- 快速解決Android7.0下沉浸式狀態(tài)欄變灰的問(wèn)題
- Android沉浸式狀態(tài)欄 + actionBar漸變 + scrollView頂部伸縮效果
- 解決Android 沉浸式狀態(tài)欄和華為虛擬按鍵沖突問(wèn)題
- Android 沉浸式狀態(tài)欄與隱藏導(dǎo)航欄實(shí)例詳解
- 詳解Android通知欄沉浸式/透明化完整解決方案
相關(guān)文章
popupwindow焦點(diǎn)問(wèn)題解決方案
在android 開發(fā)過(guò)程中,總會(huì)遇到一些問(wèn)題,比如popupwindow焦點(diǎn)問(wèn)題等等,我們?cè)撊绾谓鉀Q呢?需要的朋友可以了解下2012-11-11
這篇文章主要為大家詳細(xì)介紹了Android中Handler機(jī)制的使用,文中的示例代碼講解詳細(xì),有需要的朋友可以借鑒參考下,希望能夠?qū)Υ蠹矣兴鶐椭?/div> 2022-11-11
Android Studio中Run按鈕是灰色的快速解決方法
這篇文章主要介紹了Android Studio中Run按鈕是灰色的快速解決方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-03-03
Android微信右滑退出功能的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android微信右滑退出功能的實(shí)現(xiàn)代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-01-01
解析android res 運(yùn)行錯(cuò)誤的問(wèn)題
本篇文章是對(duì)android中res運(yùn)行錯(cuò)誤的問(wèn)題進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06最新評(píng)論

