2015-10-08 8 views
0

我为一个活动创建了此布局文件@+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"/> 
+0

就像一句话,我注意到你没有指定默认为水平的方向 –

回答

0

用于线性布局的默认取向是水平的。

我只需将父线性布局设置为垂直方向。

android:orientation="vertical" 
0

我固定它^^ 了,因为你没有match_parent在rectangle_at_the_bottom高度值! 更改为:

<View 
android:id="@+id/rectangle_at_the_bottom" 
android:layout_width="match_parent" 
android:layout_height="10dp" 
android:background="#000000"/>