0

アクティビティにドロワーを追加するためにMaterialDrawerライブラリを使用しています。アクティビティには、半透明のステータス バーが必要です。下の写真のように:

ここに画像の説明を入力

これは、ライブラリがまだ追加されていないときのアクティビティの最初の部分です。

ライブラリを使用してドロワーを追加すると:

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();
    }
}

私はこの結果を得るでしょう:

ここに画像の説明を入力

ステータス バーは明らかに半透明ではなく、アクティビティ コンテンツはその下にありません。

ただし、引き出しを開くと、ステータスバーの下に移動します。

ここに画像の説明を入力

また、これは私が活動に適用しているテーマです。

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

ここで何が問題なのですか?

4

1 に答える 1

1

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

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.

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();

This will also make your NavigationBar translucent.

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

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

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

And then build the drawer as shown here:

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

于 2015-09-28T09:44:47.497 に答える