实现if / else

时间:2015-10-15 03:15:12

标签: android string if-statement

如果Android版本高于5.X.X,我想实现此代码来设置导航栏的颜色:

我如何实现if语句?

  • 编辑:

对于那些想要:

的人
String _OSVERSION =
        android.os.Build.VERSION.RELEASE;

    if (_OSVERSION.toString().startsWith("5"))
    {
        Toast.makeText(getApplicationContext(), "Your Android Version are: \n\n" + _OSVERSION, Toast.LENGTH_SHORT).show();
        Window window = this.getWindow();

        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        window.setStatusBarColor(this.getResources().getColor(R.drawable.indigodark));

        window.setNavigationBarColor(this.getResources().getColor(R.drawable.indigodark));

    }

    else if (_OSVERSION.toString().startsWith("6"))
    {

        Window window = this.getWindow();

        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        window.setStatusBarColor(this.getResources().getColor(R.drawable.indigodark));

        window.setNavigationBarColor(this.getResources().getColor(R.drawable.indigodark));

    }

    else
    {
        Toast.makeText(getApplicationContext(), "Your android version is under 5.X.X", Toast.LENGTH_SHORT).show();
    }

1 个答案:

答案 0 :(得分:0)

使用此:

if ( Build.VERSION.SDK_INT >=
          Build.VERSION_CODES.LOLLIPOP ) {

//Code
}