1

我需要在狀態欄下面顯示圖像(狀態欄必須是透明的,不知道如何),但我無法使它工作,我已經嘗試了很多佈局示例。
這是我的XML佈局:Imageview not applying fitSystemWindows

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:wheel="http://schemas.android.com/apk/res-auto" 
android:id="@+id/rootLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context=".activities.FullScreenPlayer"> 

<com.intaj.sawt.customviews.SquareImageView 
    android:id="@+id/imgViewCover" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:scaleType="centerCrop" 
    android:src="@drawable/cover_holder" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/imgViewCover" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/full_screen_player_bg" 
     android:orientation="vertical" 
     android:padding="5dp"> 

     <TextView 
      android:id="@+id/txtSongTitle" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:textAppearance="@android:style/TextAppearance.Medium" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtArtistName" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:textAppearance="@android:style/TextAppearance.Medium" /> 

    </LinearLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="48dp"> 

     <TextView 
      android:id="@+id/startText" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_marginLeft="16dp" 
      android:layout_marginStart="16dp" 
      android:gravity="center_vertical" 
      android:maxLines="1" 
      android:textColor="@android:color/white" /> 

     <SeekBar 
      android:id="@+id/seekBar1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_gravity="center" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_toEndOf="@+id/startText" 
      android:layout_toLeftOf="@+id/endText" 
      android:layout_toRightOf="@+id/startText" 
      android:layout_toStartOf="@+id/endText" /> 

     <TextView 
      android:id="@+id/endText" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignWithParentIfMissing="true" 
      android:layout_marginEnd="16dp" 
      android:layout_marginRight="16dp" 
      android:gravity="center_vertical" 
      android:maxLines="1" 
      android:textColor="@android:color/white" /> 

    </RelativeLayout> 

    <LinearLayout 
     android:id="@+id/layoutPlaybackControls" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:orientation="horizontal" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp"> 

     <ImageView 
      android:id="@+id/repeat" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_action_repeat" 
      android:tint="@color/colorAccent" /> 

     <ImageView 
      android:id="@+id/prev" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_skip_previous_white_48dp" 
      android:tint="@color/colorAccent" /> 

     <ImageView 
      android:id="@+id/playPause" 
      android:layout_width="0dp" 
      android:layout_height="70dp" 
      android:layout_weight="1" 
      android:src="@drawable/ic_play_arrow_white_48dp" 
      android:tint="@color/colorAccent" /> 

     <ImageView 
      android:id="@+id/next" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_skip_next_white_48dp" 
      android:tint="@color/colorAccent" /> 

     <ImageView 
      android:id="@+id/shuffle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_action_shuffle" 
      android:tint="@color/colorAccent" /> 

    </LinearLayout> 

</LinearLayout> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    app:layout_collapseMode="pin" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> 

<com.pnikosis.materialishprogress.ProgressWheel 
    android:id="@+id/progressBar" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_centerInParent="true" 
    android:layout_centerVertical="true" 
    android:visibility="invisible" 
    wheel:matProg_barColor="@color/colorAccentSettings" 
    wheel:matProg_progressIndeterminate="true" /> 

這是結果:
正如你所看到的,在狀態欄沒有得到透明或圖像不低於它。

enter image description here

我後我的風格:

styles.xml

<style name="AppTheme" parent="AppTheme.Light" /> 
<!--<style name="AppThemeDark" parent="AppTheme.Dark" />--> 

<style name="AppTheme.Light" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!--light--> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="android:textColorPrimary">@color/textPrimaryColor</item> 
    <item name="android:textColorSecondary">@color/colorPrimaryDark</item> 
    <item name="android:windowBackground">@color/windowBackground</item> 
</style> 

styles.xml(V21)

<style name="AppTheme" parent="AppTheme.Light"> 
    <item name="android:windowTranslucentStatus">true</item> 
    <!--<item name="android:statusBarColor">@android:color/transparent</item>--> 
    <item name="android:windowContentTransitions">true</item> 
    <item name="android:windowAllowEnterTransitionOverlap">true</item> 
    <item name="android:windowAllowReturnTransitionOverlap">true</item> 
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item> 
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item> 
</style> 

請幫助!

+0

你在Android 4.4或更低的測試?這應該只適用於我認爲的棉花糖。 –

+0

我現在正在Android 5.0.1上進行測試,對於較低版本的相同結果 – gustav12

回答

2

試試這個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     xmlns:wheel="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/rootLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     tools:context=".activities.FullScreenPlayer"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_collapseMode="pin" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> 

<com.intaj.sawt.customviews.SquareImageView 
    android:id="@+id/imgViewCover" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    android:layout_below="@id/toolbar" 
    android:scaleType="centerCrop" 
    android:src="@drawable/cover_holder" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/imgViewCover" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/full_screen_player_bg" 
     android:orientation="vertical" 
     android:padding="5dp" > 

     <TextView 
      android:id="@+id/txtSongTitle" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:textAppearance="@android:style/TextAppearance.Medium" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtArtistName" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:textAppearance="@android:style/TextAppearance.Medium" /> 
    </LinearLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="48dp" > 

     <TextView 
      android:id="@+id/startText" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_marginLeft="16dp" 
      android:layout_marginStart="16dp" 
      android:gravity="center_vertical" 
      android:maxLines="1" 
      android:textColor="@android:color/white" /> 

     <SeekBar 
      android:id="@+id/seekBar1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_gravity="center" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_toEndOf="@+id/startText" 
      android:layout_toLeftOf="@+id/endText" 
      android:layout_toRightOf="@+id/startText" 
      android:layout_toStartOf="@+id/endText" /> 

     <TextView 
      android:id="@+id/endText" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignWithParentIfMissing="true" 
      android:layout_marginEnd="16dp" 
      android:layout_marginRight="16dp" 
      android:gravity="center_vertical" 
      android:maxLines="1" 
      android:textColor="@android:color/white" /> 
    </RelativeLayout> 

    <LinearLayout 
     android:id="@+id/layoutPlaybackControls" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:orientation="horizontal" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp" > 

     <ImageView 
      android:id="@+id/repeat" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_action_repeat" 
      android:tint="@color/colorAccent" /> 

     <ImageView 
      android:id="@+id/prev" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_skip_previous_white_48dp" 
      android:tint="@color/colorAccent" /> 

     <ImageView 
      android:id="@+id/playPause" 
      android:layout_width="0dp" 
      android:layout_height="70dp" 
      android:layout_weight="1" 
      android:src="@drawable/ic_play_arrow_white_48dp" 
      android:tint="@color/colorAccent" /> 

     <ImageView 
      android:id="@+id/next" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_skip_next_white_48dp" 
      android:tint="@color/colorAccent" /> 

     <ImageView 
      android:id="@+id/shuffle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_action_shuffle" 
      android:tint="@color/colorAccent" /> 
    </LinearLayout> 
</LinearLayout> 

<com.pnikosis.materialishprogress.ProgressWheel 
    android:id="@+id/progressBar" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_centerInParent="true" 
    android:layout_centerVertical="true" 
    android:visibility="invisible" 
    wheel:matProg_barColor="@color/colorAccentSettings" 
    wheel:matProg_progressIndeterminate="true" /> 

    </RelativeLayout> 
+0

是的,我試過了,結果相同。謝謝! – gustav12

+0

如果答案適合您,請接受答案。 –

+1

不,它不工作,正如我之前所說,與初始 – gustav12