kanytu / android-material-drawer-template

An Android template with navigation drawer for material design
Apache License 2.0
674 stars 217 forks source link

Using ScrimInsetLayout to display navigation drawer behind toolbar #20

Closed demandedcross closed 9 years ago

demandedcross commented 9 years ago

Is this possible? My code is as follows but it doesn't seem to work. The content is behind the status bar but I don't get the gray inset, just whatever color I set my status bar to i.e primarycolordark

activity_main.xml

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:fitsSystemWindows="true">

<!-- Your normal content view -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- We use a Toolbar so that our drawer can be displayed
         in front of the action bar -->
    <include layout="@layout/toolbar"/>

    <!-- The rest of your content view -->
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</LinearLayout>

    <!-- The navigation drawer -->

        <fragment
            android:id="@+id/fragment_drawer"
            android:name="example"
            android:layout_width="@dimen/drawer_width"
            android:layout_height="match_parent"
            android:layout_gravity="left|start"
            />

</android.support.v4.widget.DrawerLayout> 

fragment_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<uk.co.example.utils.ScrimInsetsFrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrimInsetsFrameLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:elevation="10dp"
    android:fitsSystemWindows="true"
    app:insetForeground="#4000">
<android.support.v7.widget.RecyclerView
    android:id="@+id/drawerList"
    android:layout_width="match_parent"
    android:clickable="true"
    android:focusableInTouchMode="true"
    android:scrollbars="vertical"
    android:focusable="true"
    android:layout_height="fill_parent"
    android:background="@color/nav_background"

    />
   </uk.co.example.utils.ScrimInsetsFrameLayout>

MainActivity onCreate method

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        ButterKnife.inject(this);
        setSupportActionBar(mToolbar);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerLayout.setStatusBarBackgroundColor(
                getResources().getColor(R.color.bayer_dark_green));

        mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.fragment_drawer);
        mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
    }

styles-v21

<style name="AppTheme.21" parent="AppTheme">

        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
kanytu commented 9 years ago

This doesn't seem to be an issue associated with this project. Have you tried a forum for the effect? Also post some prints could help solving the problem.

demandedcross commented 9 years ago

To me it seems like a problem due to using a fragment to load in the drawer, I may be wrong however. I followed answers on SO to get to the point I'm at, there's nothing different between the answers there and what I have aside from the way the drawer itself is implemented. I'll post an issue on SO though if that would be more appropriate.

kanytu commented 9 years ago

If your issues is your system bar not getting the color you defined I had the same problem before. Check this commit that fixed the issue: 2f680b765de470aa7c8f83d65923708ffae67672

demandedcross commented 9 years ago

I don't think that helps, no matter, I'll ask on SO. But maybe as an improvement to your template, look at using ScrimInsetLayout to display under and through the status bar as a few apps are doing this now and I think it would be a good addition :)

kanytu commented 9 years ago

Could you post your behavior and some expected behavior? screenshots preferably. Also what is the code of your ScrimInset Layout?

demandedcross commented 9 years ago

Can't really post screenshots I'm afraid, expected behaviour is like that in Hangouts or the Play store, behaviour I'm getting is a solid status bar, content is behind it though. Also I meant ScrimInsetFrameLayout, found here: https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/ScrimInsetsFrameLayout.java

after following answers on SO such as this one: http://stackoverflow.com/questions/26745300/navigation-drawer-semi-transparent-over-status-bar-not-working

kanytu commented 9 years ago

Could you check this branch? https://github.com/kanytu/android-material-drawer-template/tree/testing_systembar

Edit: and remove your ScrimInsetsFrameLayout.java from the xml

demandedcross commented 9 years ago

It's the other way round, if you add the ScrimInsetsFrameLayout to your Fragment_navigation_drawer.xml so it looks like

<?xml version="1.0" encoding="utf-8"?>
<com.poliveira.apps.materialtests.ScrimInsetsFrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrimInsetsFrameLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:elevation="10dp"
    android:fitsSystemWindows="true"
    app:insetForeground="#4000">
<android.support.v7.widget.RecyclerView
    android:id="@+id/drawerList"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:clickable="true"
    android:focusableInTouchMode="true"
    android:scrollbars="vertical"
    android:focusable="true"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent"
    android:background="@color/myDrawerBackground"/>

    </com.poliveira.apps.materialtests.ScrimInsetsFrameLayout>

then you get the desired effect, I still can't get it to work on my project however but going off this branch I should be able to figure out the problem now hopefully.

kanytu commented 9 years ago

Notice the changes I made in the commit. You will have to set the android:statusBarColor in styles.xml to transparent and then change it's color programmatically.

demandedcross commented 9 years ago

I'm doing that :/ not sure what else I'm missing right now, I feel like I've got everything you changed for this branch, but maybe i added something else that's affecting it.

demandedcross commented 9 years ago

Not sure exactly what the issue was but I copied your styles v21 over and it's working how it should now. Thanks for your help even though it wasn't an issue with your code :)