Cannot change color of progress bar? - android

Created own color in color.xml <color name="colorProgressBar">#006600</color>
In styles.xml
<style name="ProgressBarde">
<item name="colorAccent">#color/colorProgressBar</item>
</style>
and added this to the main .xml activity
<ProgressBar
android:id="#+id/progressBar3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:theme="#style/ProgressBarde" />
As you can the I choosed green color for my progress bar. It's even changed to my android studio editor. But when run it on my real android device by usb It's not changing. Where is my mistake?

Are you running your app on a pre-Lollipop device? On these devices the Material-themed progress bars are not available. instead, they are replaced with the default Holo progress bar. You can try using a third-party library for this.
(This should have been a comment, but my reputation is too low.)

Related

Drawable Tinting: Indeterminate ProgressBar [duplicate]

I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="#android:style/Widget.Material.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
I have a Nexus 5 running Android 5.0.1 that doesn't display the ProgressBar, obviously because of the style. When I set the style for example to
style="#android:style/Widget.ProgressBar.Large"
or
style="#android:style/Widget.Holo.ProgressBar.Large"
it is shown. I have an identical Nexus 5 also running Android 5.0.1 which displays all the ProgressBars fine.
Enabling the 'draw layout borders' option in the developers options, it shows that the ProgressBar is included in the layout, it is simply not shown.
This seems very strange, any idea on what could be going on here?
I was having the same issue but was because the developer phone have animations scales to 0 (all 3).
Enable all the animations on the device and maybe you will be able to see the progress bar, so for normal people that will have animations enabled the progress bar will appear fine.
In my case, it looks as if the issue is with build LRX22G:
Nexus 7 using Build LRX22G (android-5.0.2_r1) - progress bar not shown
Nexus 5 using Build LRX22C (android-5.0.1_r1) - progress bar shown
See https://source.android.com/source/build-numbers.html
It's probably also related with https://code.google.com/p/android/issues/detail?id=77865
Not being able to wait for a fix, what I've decided to do is to force the Holo progress bar to be used in my Material theme. This is how it was achieved - it may be of some use to you in the meantime:
<style name="AppBaseTheme" parent="#android:style/Theme.Material.Light.DarkActionBar">
<!-- Build LRX22G (5.0.2 Nexus 7) fails to display progress bar so we'll use Holo instead of Material -->
<!-- http://stackoverflow.com/questions/27567235/certain-progressbar-styles-not-shown-on-nexus-5-android-5-0-1 -->
<item name="android:progressBarStyleSmall">#style/MaterialProgressBarFix.Small</item>
<item name="android:progressBarStyle">#style/MaterialProgressBarFix</item>
<item name="android:progressBarStyleLarge">#style/MaterialProgressBarFix.Large</item>
</style>
<style name="MaterialProgressBarFix.Small" parent="#android:style/Widget.Holo.ProgressBar.Small" />
<style name="MaterialProgressBarFix" parent="#android:style/Widget.Holo.ProgressBar" />
<style name="MaterialProgressBarFix.Large" parent="#android:style/Widget.Holo.ProgressBar.Large" />
By setting the style to the following instead you should be able to debug this issue
style="?android:attr/progressBarStyleLarge"

How to change default ProgressBar circle color on Android

I am currently using an external library in my Android project imported via gradle.
This library show a notification bar with a ProgressBar circle.
This is the code I found in it's sources :
<ProgressBar
android:id="#+id/progress_bar"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
style="#style/SuperActivityToast_Progress_ProgressBar"/>
The style associated is this one :
<style name="SuperActivityToast_Progress_ProgressBar" parent="android:Widget.Holo.ProgressBar">
<item name="android:layout_width">32dp</item>
<item name="android:layout_marginLeft">8dp</item>
</style>
If I understand correclty, the color of the circle shown is derived from the default one ( green on my phone ).
I need to change it!
Now, I can't modify the source code, and the library itself doesn't offer me the possibility to set the style programmatically.
There is a way to change the default style at app level or better override this specific style?
Thanks
Davide
If you are using the AppCompat theme, it uses the accentColor to tint the circle.
If you want to tint it to a different color than the Theme, then you should consider using ThemeOverylay. E.g. If you want to make the circle tint red you could do the following:
in your styles.xml
<style name="RedAccent" parent="ThemeOverlay.AppCompat.Light">
<item name="colorAccent">#F00</item>
</style>
in your ProgressBar, set the theme to be RedAccent.
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="32dp"
android:layout_height="32dp"
android:theme="#style/RedAccent"/>
And your circle will now be in red color!
After several attempts I found a solution :
ProgressBar progBar = (ProgressBar) context.getActivity().findViewById(R.id.progress_bar);
if (progBar != null) {
progBar.setVisibility(View.VISIBLE);
progBar.setIndeterminate(true);
progBar.getIndeterminateDrawable().setColorFilter(0xFFFFFFFF, android.graphics.PorterDuff.Mode.MULTIPLY);
}
Simply, i'll get a reference of the progress bar object created by the library and i change it's attributes. ( in my activity i must do that in a "OnStart" method otherwise it is null )
The most important part is the "setColorFilter" that do the magic.
For future references, this change has worked for me is:
Changing the colorControlActivated within AppTheme in your values/styles.xml file:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Main theme colors -->
....
<!-- Color for circle in progress bar -->
<item name="colorControlActivated">#DC0808</item>
</style>
With this approach, you do not need to perform any action on your <ProgressBar/> tag within your xml file.
Just add color in ProgressBar like below :
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:visibility="gone"
android:indeterminateTint="#color/colorPrimary" // add color here
android:layout_centerVertical="true"/>

Appcompat v7 Material checkbox changing color to default black in Lollipop devices

I am using appcompat v7 material checkbox. My project theme is light blue, so I am assigning light blue for my checkbox checked color in styles.xml as follows
<!--checked color-->
<item name="colorAccent">#color/light_blue</item>
<!--un checked color-->
<item name="android:textColorSecondary">#color/secondary_text</item>
In My layout file
<CheckBox
android:id="#+id/chk_tick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/abc_btn_check_material"
android:layout_gravity="center"/>
Everything works fine with the versions below kitkat's, but the problem arises only with lollipop versions ( By default it is automatically assigning black color ). I really dont know why it is happening. Kindly please help me with your solutions. Thanks in advance
Remove this line:
android:button="#drawable/abc_btn_check_material"
Your CheckBox should be styled automatically, without setting android:button property.
Use AppCombat check box for best result
<android.support.v7.widget.AppCompatCheckBox
android:id="#+id/chkSelected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
/>
After this go to styles.xml and create new styles as follows
<style name="SampleTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorSecondary">#color/red</item>
</style>
This is not done yet go to your manifest xml
<activity
android:name=".yourActivity"
android:theme="#style/SampleTheme" />
This Works on pre_lollipop devices also. Happy coding :)

Samsung device with Android 5.0 changes progressbar color

Samsung devices with Android 5.0 ignore my color for the progressbar (set in styles.xml). The default blue color of samsung is used instead.
<style name="Progress">
<item name="colorControlActivated">#000000</item>
</style>
The progressbar is in a toolbar:
<android.support.v7.widget.Toolbar
...
>
<ProgressBar
android:id="#+id/progress_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:theme="#style/Progress"/>
</android.support.v7.widget.Toolbar>
Any ideas?
As far as I remember, this topic will help: https://medium.com/the-wtf-files/the-misterious-case-of-the-skewed-progressbar-75da47ddd767.
You should add an attribute: android:indeterminateDrawable="#drawable/progressbar" to a ProgressBar and also add a drawable. It is useful for infinite ProgressBar. If it's determinate, I will research a problem and report here. Also see: How to change color in circular progress bar?.
For those who don't see a ProgressBar at all, see https://github.com/DreaminginCodeZH/MaterialProgressBar/issues/1. Maybe an "Animation scale" in Developer Options of your device is turned off.
See also: https://github.com/DreaminginCodeZH/MaterialProgressBar.

Certain ProgressBar styles not shown on Nexus 5 Android 5.0.1

I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="#android:style/Widget.Material.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
I have a Nexus 5 running Android 5.0.1 that doesn't display the ProgressBar, obviously because of the style. When I set the style for example to
style="#android:style/Widget.ProgressBar.Large"
or
style="#android:style/Widget.Holo.ProgressBar.Large"
it is shown. I have an identical Nexus 5 also running Android 5.0.1 which displays all the ProgressBars fine.
Enabling the 'draw layout borders' option in the developers options, it shows that the ProgressBar is included in the layout, it is simply not shown.
This seems very strange, any idea on what could be going on here?
I was having the same issue but was because the developer phone have animations scales to 0 (all 3).
Enable all the animations on the device and maybe you will be able to see the progress bar, so for normal people that will have animations enabled the progress bar will appear fine.
In my case, it looks as if the issue is with build LRX22G:
Nexus 7 using Build LRX22G (android-5.0.2_r1) - progress bar not shown
Nexus 5 using Build LRX22C (android-5.0.1_r1) - progress bar shown
See https://source.android.com/source/build-numbers.html
It's probably also related with https://code.google.com/p/android/issues/detail?id=77865
Not being able to wait for a fix, what I've decided to do is to force the Holo progress bar to be used in my Material theme. This is how it was achieved - it may be of some use to you in the meantime:
<style name="AppBaseTheme" parent="#android:style/Theme.Material.Light.DarkActionBar">
<!-- Build LRX22G (5.0.2 Nexus 7) fails to display progress bar so we'll use Holo instead of Material -->
<!-- http://stackoverflow.com/questions/27567235/certain-progressbar-styles-not-shown-on-nexus-5-android-5-0-1 -->
<item name="android:progressBarStyleSmall">#style/MaterialProgressBarFix.Small</item>
<item name="android:progressBarStyle">#style/MaterialProgressBarFix</item>
<item name="android:progressBarStyleLarge">#style/MaterialProgressBarFix.Large</item>
</style>
<style name="MaterialProgressBarFix.Small" parent="#android:style/Widget.Holo.ProgressBar.Small" />
<style name="MaterialProgressBarFix" parent="#android:style/Widget.Holo.ProgressBar" />
<style name="MaterialProgressBarFix.Large" parent="#android:style/Widget.Holo.ProgressBar.Large" />
By setting the style to the following instead you should be able to debug this issue
style="?android:attr/progressBarStyleLarge"

Categories

Resources