android – 如何将透明状态栏下的ImageView

在下面的图片中,我试图将
ImageView置于StatusBar下.但它没有发生.

Image Screenshot on Android API 19

Image Screenshot on Android API 22

我继续Android transparent status bar and actionbar(这个问题)并尝试实现相同但不起作用.

活动的xml布局是

<?xml version="1.0" encoding="utf-8"?>
 <FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/category_layout_top"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<ImageView
    android:fitsSystemWindows="true"
    android:layout_width="390dp"
    android:layout_height="390dp"
    android:id="@+id/category_Image_View"/>


    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/def_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="#00FFFFFF"
        android:layout_alignParentTop="true" />




</FrameLayout>
<LinearLayout
 android:layout_width="match_parent"
 android:layout_height="50dp"
 android:id="@+id/category_linearlayout">
<TextView android:layout_width="match_parent"
android:layout_height="match_parent"
android:singleLine="true"
android:id="@+id/category_textView"
/>
</LinearLayout>

</LinearLayout>

</FrameLayout>

我也在onCreate()方法中尝试了下面的代码

 setStatusBarTranslucent(true);



protected void setStatusBarTranslucent(boolean makeTranslucent) {
    if (makeTranslucent) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    } else {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
}

style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

</style>

风格v21.xml

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

AppTheme是活动中使用的风格.

编辑1

我在FrameLayout的背景中使用了一种颜色来检查它是否在状态栏下面.事实并非如此.

所以问题不在于布局,我想.

编辑2
这是理想的结果
《android – 如何将透明状态栏下的ImageView》

最佳答案 在style-v21中,您将覆盖AppTheme.NoActionBar样式,但您说您在活动中使用的样式是AppTheme样式.

您需要在style-v21中覆盖AppTheme布局或在活动中定义AppTheme.NoActionBar.

点赞