Common background image for Actionbar (Toolbar) and statusbar
Asked Answered
C

1

6

I need to design something like this with Transparent Toolbar

this

But I am getting something like this

this

Design is like

  • transparent statusbar and actionbar with background image
  • actionbar must be below the statusbar

This is my code

App Theme

  <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

 <style name="AppTheme.TransparentStatusBar" parent="AppTheme">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>

</style>

XML

<android.support.v4.widget.DrawerLayout 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"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_home"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_home"
    app:menu="@menu/activity_home_drawer" />

<android.support.design.widget.CoordinatorLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context="activities.HomeActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/float_transparent"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/float_transparent"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_home" />

  <android.support.v4.widget.NestedScrollView 
    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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="activities.HomeActivity"
    tools:showIn="@layout/app_bar_home">
   <!-- app:layout_behavior="@string/appbar_scrolling_view_behavior"-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:scaleType="fitXY"
        android:src="@drawable/home_top_image"
       />
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

I already tried several answers . but none of those worked. And also added this

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window w = getWindow(); // in Activity's onCreate() for instance
        w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }

But I am getting an overlapped toolbar like this

enter image description here

This is not what I want. Please help..

Cannikin answered 23/8, 2017 at 9:56 Comment(3)
You should change your primary color and primary dark color to transparent colorTredecillion
Already tried that. it shows statusbar with a dark shadeCannikin
maybe your appbar is having some other color with the background of AppBarLayout, you have to keep every color sameTredecillion
T
2

to set image in action make your toolbar like this

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/float_transparent"
    app:popupTheme="@style/AppTheme.PopupOverlay" >


    <ImageView
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:scaleType="fitXY"
      android:src="@drawable/home_top_image"
   />
 </android.support.v7.widget.Toolbar>

and in activity theme m change your primary color and primary dark color to transparent color

like this

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  <!-- Customize your theme here. -->
  <item name="colorPrimary">@android:color/transparent</item>
  <item name="colorPrimaryDark">@android:color/transparent</item>
  <item name="colorAccent">@color/colorAccent</item>
  <item name="android:windowTranslucentStatus">true</item>
  <item name="android:windowTranslucentNavigation">true</item>
 </style>
Tinct answered 23/8, 2017 at 10:1 Comment(19)
It changed the statusbar color to grey. like this imgur.com/6xLn8qyCannikin
Putting imageview inside toolbar won't fit inside. Image height is 300dp.Cannikin
@VinayakB than you need to give hight of imageview as per actionbar hight like ?attr/actionBarSizeTinct
Pardon me. How can change statusbar background ? Its shows in greyCannikin
use this window.setStatusBarColor(ContextCompat.getColor(activity,R.color.my_statusbar_color));Tinct
Let us continue this discussion in chat.Tinct
i am getting stuck with same issue .. can u tell any solution is there for this issue??Plainspoken
@pallavirichhariya what issue you are facing?? can you please explain moreTinct
i am trying to give common backgroung image for toolbar and status bar .. toolbar is going top of status bar ..both backgroud is transparent so its visible but its overlappingPlainspoken
@pallavirichhariya please share your code let me checkTinct
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = getWindow(); // in Activity's onCreate() for instance w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); }Plainspoken
when i am appying this property programatically its happening otherwise its working finePlainspoken
@pallavirichhariya check this answer https://mcmap.net/q/878483/-bottomnavigationbar-underneath-navbar it has same issueTinct
not getting the solution ... i have simple toolbar in top while i am trying that property its overlappingPlainspoken
@pallavirichhariya have u tried thie if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } else { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); }Tinct
i want same background image for toolbar and status bar ...overlapping is gone but background i not same for both.Plainspoken
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = getWindow(); // in Activity's onCreate() for instance w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } with this only i m able to apply same backgroundPlainspoken
any suggestion??Plainspoken
just now i checked bottom navigation is overlapping in tab layout which is in bottomPlainspoken

© 2022 - 2024 — McMap. All rights reserved.