国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android4.4+ 實(shí)現(xiàn)半透明狀態(tài)欄(Translucent Bars)

2019-12-12 02:01:23
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Android從4.4(KitKat) 開(kāi)始進(jìn)行了一些視覺(jué)上的改善和提升,其中包括讓狀態(tài)欄(Status Bar)和下方導(dǎo)航欄(Navigation Bar)進(jìn)行半透明處理,可以使APP內(nèi)容向上下延伸,使整個(gè)畫(huà)面的利用度大幅度提升,本篇就來(lái)說(shuō)說(shuō)這個(gè)“半透明狀態(tài)欄”(Translucent Bars)。

簡(jiǎn)單做了個(gè)Demo效果如下圖

*這里解釋個(gè)誤區(qū),國(guó)內(nèi)開(kāi)發(fā)者和設(shè)計(jì)師經(jīng)常把這種半透明效果稱(chēng)為沉浸式狀態(tài)欄這是不對(duì)的, 沉浸式Immersive mode,官方解釋為hiding all system UI根本不是這種半透明的效果。

下面說(shuō)說(shuō)如何使用這種效果:

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è)簡(jiǎn)單的半透明化效果就實(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);  }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 黔西| 宾川县| 阳春市| 曲水县| 莒南县| 宁城县| 青海省| 云梦县| 离岛区| 富平县| 蒙自县| 利辛县| 鄱阳县| 霸州市| 手游| 新安县| 南岸区| 青海省| 三门峡市| 汉中市| 道孚县| 同心县| 博野县| 鄂温| 根河市| 肥城市| 盐源县| 吕梁市| 云和县| 寿光市| 图木舒克市| 西乌珠穆沁旗| 宿迁市| 天气| 宁安市| 二手房| 诸城市| 盘山县| 枣强县| 和龙市| 呼玛县|