3

I have seen in some apps the status bar color could be changed and matched to as what is being done in api level 21.

I searched and found this solution Source

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">   
<!-- Set AppCompat’s color theming attrs -->
<item name="colorPrimary">@color/my_awesome_red</item>
<item name="colorPrimaryDark">@color/my_awesome_darker_red</item>
<!-- Other attributes -->
</style>

But it is not working

This is my style code

<style name="ToolbarTheme" parent="Theme.AppCompat">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/ColorPrimary</item>
    <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
</style>
Community
  • 1
  • 1
WISHY
  • 7,590
  • 21
  • 75
  • 142
  • The StatusBar can't be tinted prior to api-level 21. – reVerse Mar 25 '15 at 08:53
  • What about this?? https://developer.android.com/training/material/compatibility.html#SupportLib – WISHY Mar 25 '15 at 09:35
  • Please see this [StackO-Post](http://stackoverflow.com/a/26623245/982852) – reVerse Mar 25 '15 at 09:39
  • I do understand the point. But I have seen apps with the colored status bar. For example sony walkman app. – WISHY Mar 25 '15 at 11:50
  • Which is a system app on Sony devices, isn't it? Most probably Sony made changes to the system itself. Unfortunately you as a developer can't use these. – reVerse Mar 25 '15 at 12:06

2 Answers2

-1

If you mean the color of AcionBar, you can change programmatically the color with this code:

getSupportActionBar().setBackgroundDrawable(new Color.Drawable(Color.rgb(120,0,47)));

Change numbers to select your own color.

Zong
  • 5,701
  • 5
  • 27
  • 46
David
  • 19
  • 2
-1

StatusBar is only for devices with API level more than 21. If your min API level is less than that then you have to do some change in your java source file. Go to the source file to which you want to add the status bar color. Then wrap the OnCreate() method with annotation @TargetApi(Build.VERSION_CODES.LOLLIPOP).

Then inside the method you have to check whether the device is capable or not as shown below.

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
 window.setStatusBarColor(getResources().getColor(R.color.Statusbar));
    }

Hope it works..!!

aravindkanna
  • 623
  • 1
  • 7
  • 22
  • This really doesn't answer the original question, they already seem to know that you can change the status bar in this way on Lollipop and above. The only solution I've been able to find that sort of works is this library: https://github.com/jgilfelt/SystemBarTint – CodyEngel Nov 01 '16 at 17:11