This Activity already has an action bar supplied by the window decor

后端 未结 21 2695
-上瘾入骨i
-上瘾入骨i 2020-11-21 23:45

Trying to move over my stuff to use Toolbar instead of action bar but I keep getting an error saying

java.lang.RuntimeException: Unable to start         


        
21条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 00:23

    Simply put, you can do the following:-

    if (android.os.Build.VERSION.SDK_INT >= 21) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
    
        }
    

提交回复
热议问题