Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bring ImageView under the transparent Status Bar

In the images below,I am trying to bring the ImageView under the StatusBar. But its not happening.

Image Screenshot on Android API 19

Image Screenshot on Android API 22

I went on Android transparent status bar and actionbar (this question) and tried to implement the same but its not working.

The xml layout of the activity is

<?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>

I tried the below code in the onCreate() method also

 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>

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 is the style used in the activity.

EDIT 1

I used a color in the background of FrameLayout to check whether it was under the status bar or not. And it is not.

So the problem is not with Layout, I guess.

EDIT 2 this is the desired result

like image 326
Abhishek Kulshrestha Avatar asked Oct 31 '22 07:10

Abhishek Kulshrestha


1 Answers

In style-v21 you are overriding the style AppTheme.NoActionBar, but you said the style you use in your activity is the AppTheme style.

You need to override the AppTheme layout in style-v21 or define AppTheme.NoActionBar in you activity.

like image 61
jonathanrz Avatar answered Nov 09 '22 06:11

jonathanrz