简体   繁体   English

Android导航抽屉未在kitkat中显示标题栏

[英]android navigation drawer not showing title bar in kitkat

In my application , i created a navigation drawer using Android studio template. 在我的应用程序中,我使用Android Studio模板创建了一个导航抽屉。 It works perfectly in Android 5.0 above devices but the title bar does not appear in Kitkat devices (only statius bar can be seen) , I was unable to find a solution, 它可以在Android 5.0以上版本的设备上完美运行,但标题栏不会出现在Kitkat设备上(只能看到状态栏),我找不到解决方案,

The below is my code 下面是我的代码

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

    } 

Thanks in advance 提前致谢

In KitKat, making the statusbar (semi-)transparent is more complex compared to Lollipop+. 在KitKat中,与Lollipop +相比,使状态栏(半)透明是更加复杂的。 So the titlebar is still there, it's just below the status bar ;) 所以标题栏仍然在那里,它就在状态栏下面;)

Edit: If you absolutely want to achieve this on KitKat, you could use a SystemBarTintManager ( https://github.com/jgilfelt/SystemBarTint/blob/master/library/src/com/readystatesoftware/systembartint/SystemBarTintManager.java ). 编辑:如果您绝对想在KitKat上实现此目的,则可以使用SystemBarTintManager( https://github.com/jgilfelt/SystemBarTint/blob/master/library/src/com/readystatesoftware/systembartint/SystemBarTintManager.java )。

But I don't recommend that, I've done it myself and it's not so easy to get it right. 但是我不建议这样做,我自己做过,要正确完成并非易事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM