MaterialDrawer图书馆变成半透明状态栏变成不透明1 [英] MaterialDrawer library turns a translucent status bar into a opaque one

查看:838
本文介绍了MaterialDrawer图书馆变成半透明状态栏变成不透明1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MaterialDrawer 库增加一个抽屉我的活动。这些活动必须有半透明的状态栏。像下面的图片:

I am using MaterialDrawer library for adding a drawer to my activities. The activities must have translucent status bar. Like the picture below:

在这里输入的形象描述

这是我的活动的顶部,当库尚未添加它。

This is the top part of my activity, when the library has not added to it yet.

当我使用该库添加一个抽屉:

When I add a drawer using the library:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        DrawerMenu.addTo(this);
    }

}

以及 DrawerMenu 辅助类:

public class DrawerMenu {
    public static void addTo(final Activity activity) {
        AccountHeader headerResult = new AccountHeaderBuilder()
            .withActivity(activity)
            .withHeaderBackground(R.drawable.drawer_header)
            .addProfiles(
                    new ProfileDrawerItem()
                            .withName("Ashkan")
                            .withEmail("ashkan@sarlak.com")
                            .withIcon(ContextCompat.getDrawable(activity, R.drawable.profile_pic))
            )
            .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
                @Override
                public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
                    return false;
                }
            })
            .build();

        new DrawerBuilder()
            .withActivity(activity)
            .withAccountHeader(headerResult)
            .addDrawerItems(new PrimaryDrawerItem().withName("Login"))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int i, IDrawerItem iDrawerItem) {
                    Toast.makeText(activity, "Login!!!", Toast.LENGTH_LONG).show();
                    return true;
                }
            })
            .build();
    }
}

我会得到这样的结果:

I will get this result:

在这里输入的形象描述

状态栏显然是不透光和活动的内容是不是它下面。

The status bar is obviously non translucent and activity content is not below it.

然而,当我打开抽屉,这是不言而喻的状态栏下方:

However when I open the drawer, it goes beneath the status bar:

在这里输入的形象描述

另外这是我申请的活动主题是:

Also this is the theme that I'm applying to the activity:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">false</item>
</style>

有什么问题吗?

推荐答案

您已经张贴看起来像你的应用程序应该在全屏模式下显示的屏幕截图。

The screenshot you have posted looks like your app should be displayed in fullscreen mode.

因此​​,与您发布使用 MaterialDrawer 基本配置的截图。
在大多数情况下,谁使用抽屉人们希望自己的内容(包括在工具栏)下方显示在状态栏,但在抽屉后面的<强>状态栏即可。那么,基本上发生在这里的是,在 MaterialDrawer 的逻辑将设置你的应用程序到半透明的状态栏模式,这样的内容将它后面移动。此外,它会添加 ScrimInsetsFrameLayout 然后将填充添加到顶部,这样的内容将低于在状态栏即可。

So with the screenshots you posted you use the basic configuration of the MaterialDrawer. In most cases people who use the drawer want their content (including the Toolbar) to be displayed below the StatusBar but the drawer behind the StatusBar. So what basically happens here is that the logic of the MaterialDrawer will set your app into the translucent StatusBar mode so the content will move behind it. Additionally it will add the ScrimInsetsFrameLayout which will then add the padding to the top so the content will be below the StatusBar.

在你的情况下,你希望你的内容也走在后面的状态栏,所以你也想将您的内容后的状态栏即可。

In your case you want your content also to go behind the StatusBar so you want to also move your content behind the StatusBar.

这可以通过添加 withFullscreen(真)标记到 MaterialDrawer的生成器实施

This can be implemented by adding the withFullscreen(true) flag to the Builder of the MaterialDrawer

这是它是如何使用编程方式完成

This is how it's done programmatically

//Create the drawer
result = new DrawerBuilder()
    .withActivity(this)
    .withFullscreen(true)
    .withSavedInstance(savedInstanceState)
    .build();

这也将让您的导航栏透亮。

有就是这个话题,这将很可能也在这里提高行为的悬而未决的问题。
https://github.com/mikepenz/MaterialDrawer/issues/698

There is an open issue about this topic which will probably also improve the behavior here. https://github.com/mikepenz/MaterialDrawer/issues/698

所以,实施额外的标志不包括 ScrimInsetsFrameLayout
https://github.com/mikepenz/MaterialDrawer/issues/698#issuecomment-143674729

So implementing an additional flag to don't include the ScrimInsetsFrameLayout https://github.com/mikepenz/MaterialDrawer/issues/698#issuecomment-143674729

好吧作为加法。如果你只想在状态栏以是半透明的。那么你必须做以下几点。
使用 TranslucentStatus 主题(或它的孩子)中的一个为这项活动

Ok as an addition. If you want just the StatusBar to be translucent. then you have to do following. Use one of the TranslucentStatus themes (or a child of it) for this activity

@style/MaterialDrawerTheme.Light.TranslucentStatus

和再建抽屉如下所示:

//Create the drawer
result = new DrawerBuilder()
    .withActivity(this)
    .withFullscreen(true)
    .withTranslucentNavigationBarProgrammatically(false)
//note that the translucentNavigationBarProgrammatically comes AFTER the withFullscreen method

这将导致一个透明的状态栏,但采用了黑色的导航栏

This will result in an transparent StatusBar but with a black NavigationBar

这篇关于MaterialDrawer图书馆变成半透明状态栏变成不透明1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆