android导航抽屉在kitkat中没有显示标题栏



在我的应用程序中,我使用Android studio模板创建了一个导航抽屉。它在Android 5.0以上的设备中工作得很好,但标题栏没有出现在Kitkat设备中(只能看到静态栏),我找不到解决方案,

下面是我的代码

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().show();

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar,R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();
        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        Intent intent = getIntent();
        linkNo = intent.getIntExtra(FirstMenuFragment.LINK_NO, 0);
        //Make firstItem active
        navigationView.getMenu().getItem(linkNo).setChecked(true);
    } 

提前感谢

在KitKat中,与Lollipop+相比,使statusbar(半透明)透明更复杂。所以标题栏仍然存在,它就在状态栏的下面;)

编辑:如果你绝对想在KitKat上实现这一点,你可以使用SystemBarTintManager(https://github.com/jgilfelt/SystemBarTint/blob/master/library/src/com/readystatesoftware/systembartint/SystemBarTintManager.java)。

但我不建议这样做,我自己做过,要把它做好并不容易。

最新更新