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

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Vinayak B
  • 4,430
  • 4
  • 28
  • 58

1 Answers1

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>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • It changed the statusbar color to grey. like this http://imgur.com/6xLn8qy – Vinayak B Aug 23 '17 at 10:12
  • Putting imageview inside toolbar won't fit inside. Image height is 300dp. – Vinayak B Aug 23 '17 at 10:33
  • @VinayakB than you need to give hight of imageview as per actionbar hight like ?attr/actionBarSize – AskNilesh Aug 23 '17 at 10:34
  • Pardon me. How can change statusbar background ? Its shows in grey – Vinayak B Aug 23 '17 at 10:40
  • use this `window.setStatusBarColor(ContextCompat.getColor(activity,R.color.my_statusbar_color));` – AskNilesh Aug 23 '17 at 10:46
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/152623/discussion-between-nilesh-rathod-and-vinayak-b). – AskNilesh Aug 23 '17 at 10:46
  • i am getting stuck with same issue .. can u tell any solution is there for this issue?? – pallavi richhariya Apr 04 '19 at 07:26
  • @pallavirichhariya what issue you are facing?? can you please explain more – AskNilesh Apr 04 '19 at 07:28
  • 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 overlapping – pallavi richhariya Apr 04 '19 at 07:32
  • @pallavirichhariya please share your code let me check – AskNilesh Apr 04 '19 at 07:32
  • 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); } – pallavi richhariya Apr 04 '19 at 07:45
  • when i am appying this property programatically its happening otherwise its working fine – pallavi richhariya Apr 04 '19 at 07:45
  • @pallavirichhariya check this answer https://stackoverflow.com/a/52341684/7666442 it has same issue – AskNilesh Apr 04 '19 at 07:48
  • not getting the solution ... i have simple toolbar in top while i am trying that property its overlapping – pallavi richhariya Apr 04 '19 at 07:55
  • @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); }` – AskNilesh Apr 04 '19 at 07:56
  • i want same background image for toolbar and status bar ...overlapping is gone but background i not same for both. – pallavi richhariya Apr 04 '19 at 08:00
  • 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 background – pallavi richhariya Apr 04 '19 at 08:02
  • any suggestion?? – pallavi richhariya Apr 04 '19 at 09:05
  • just now i checked bottom navigation is overlapping in tab layout which is in bottom – pallavi richhariya Apr 04 '19 at 13:57