我为一个活动创建了此布局文件@+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"/>
就像一句话,我注意到你没有指定默认为水平的方向 –