Navigation Drawer statusbar

て烟熏妆下的殇ゞ 提交于 2019-12-08 05:18:45

问题


I'm having trouble making Navigation drawer over statusbar.

I'm using new Design support library. In blogspot thay said:

NavigationView takes care of the scrim protection of the status bar for you, ensuring that your NavigationView interacts with the status bar appropriately on API21+ devices.

But it has no documentation so I'm very confused how to use Drawer to achieve desired effect.

I tried inserting following attributes in my styles-v21:

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>

after this Navigation drawer is working as needed but, other activities have transparent statusbar.

Can somebody give me a better solution?


回答1:


The best solution here is to create special theme for activity with navigation like this.

in styles.xml

<style name="NavigationDrawerTheme" parent="AppTheme"/>

but in styles v21 you will override this as

<style name="NavigationDrawerTheme" parent="AppTheme">
        <item name="android:statusBarColor">@android:color/transparent</item>
</style>

and in AndroidManifest.xml you will set

<activity
    android:theme="@style/NavigationDrawerTheme"
    android:name=".activities.MainActivity"
    android:label="@string/title_activity_main" />

So you will have correct behavior in all activities. :-)

P.S If someone needs more explanation, comment.



来源:https://stackoverflow.com/questions/31369243/navigation-drawer-statusbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!