我爲一個活動創建了此佈局文件@+id/activity_play_panel
。將狀態欄顏色設置爲透明使活動中的其他視圖透明
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_play_panel"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.michael.musicplayer.PlayPanel">
<View
android:id="@+id/rectangle_at_the_top"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#00FFFF"/>
<View
android:id="@+id/rectangle_at_the_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"/>
我加入下面的Java代碼,使黑條下方的狀態欄在@+id/activity_play_panel
tranparent。
ColorDrawable colorDrawable = new ColorDrawable(Color.TRANSPARENT);
getWindow().setBackgroundDrawable(colorDrawable);
getWindow().setStatusBarColor(Color.TRANSPARENT);
然而,經過予添加代碼以使狀態欄透明,在@+id/activity_play_panel
第二視圖也變成透明的。
如果我顛倒了視圖的順序,那麼我可以看到第二個視圖,但不是第一個視圖,例如
<!-- Not transparent-->
<View
android:id="@+id/rectangle_at_the_top"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#00FFFF"/>
<!-- Transparent-->
<View
android:id="@+id/rectangle_at_the_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"/>
或者對反轉
<!-- Not transparent-->
<View
android:id="@+id/rectangle_at_the_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"/>
<!-- Transparent-->
<View
android:id="@+id/rectangle_at_the_top"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#00FFFF"/>
就像一句話,我注意到你沒有指定默認爲水平的方向 –