這篇文章將為大家詳細(xì)講解有關(guān)Android4.4+怎么實(shí)現(xiàn)半透明狀態(tài)欄,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
Android從4.4(KitKat) 開始進(jìn)行了一些視覺上的改善和提升,其中包括讓狀態(tài)欄(Status Bar)和下方導(dǎo)航欄(Navigation Bar)進(jìn)行半透明處理,可以使APP內(nèi)容向上下延伸,使整個(gè)畫面的利用度大幅度提升,本篇就來說說這個(gè)“半透明狀態(tài)欄”(Translucent Bars)。
簡單做了個(gè)Demo效果如下圖
*這里解釋個(gè)誤區(qū),國內(nèi)開發(fā)者和設(shè)計(jì)師經(jīng)常把這種半透明效果稱為沉浸式狀態(tài)欄這是不對(duì)的, 沉浸式Immersive mode,官方解釋為hiding all system UI根本不是這種半透明的效果。
下面說說如何使用這種效果:
1、在onCreate里面代碼設(shè)置半透明的屬性,由于只有Android 4.4以上才支持這種效果,所以代碼需要判斷下
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //透明狀態(tài)欄 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //透明底部導(dǎo)航欄 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); }
2、在這個(gè)界面上我去掉了Actionbar,實(shí)現(xiàn)方式有很多,這里我使用的是在Style里去掉。
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> </style>
3、這個(gè)部分需要留意一下,如果希望APP的顯示內(nèi)容正常和滾動(dòng)透明化需要加上android:fitsSystemWindows=”true”和android:clipToPadding=”false”的屬性,建議你把這兩個(gè)屬性好好試試加上與否的區(qū)別。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:clipToPadding="false" android:background="#795548" tools:context=".DefaultActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="#ffffff" android:text="@string/str" /> </ScrollView>
這樣一個(gè)簡單的半透明化效果就實(shí)現(xiàn)了
詳細(xì)源碼:
Layout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:clipToPadding="false" android:background="#795548" tools:context=".DefaultActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="#ffffff" android:text="@string/str" /> </ScrollView>
Style
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> </style> </resources>
MainActivity
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //透明狀態(tài)欄 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //透明導(dǎo)航欄 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } setContentView(R.layout.activity_main); }Android是什么
Android是一種基于Linux內(nèi)核的自由及開放源代碼的操作系統(tǒng),主要使用于移動(dòng)設(shè)備,如智能手機(jī)和平板電腦,由美國Google公司和開放手機(jī)聯(lián)盟領(lǐng)導(dǎo)及開發(fā)。
關(guān)于“Android4.4+怎么實(shí)現(xiàn)半透明狀態(tài)欄”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
網(wǎng)頁題目:Android4.4+怎么實(shí)現(xiàn)半透明狀態(tài)欄-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://www.chinadenli.net/article46/gschg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、定制開發(fā)、關(guān)鍵詞優(yōu)化、軟件開發(fā)、做網(wǎng)站、網(wǎng)站營銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容