I created this progress bar for my app, but I cant get that yellow orangy color that appears to change to something like red or blue.
<ProgressBar
android:id="#+id/progress_bar"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_width="250sp"
android:layout_height="wrap_content"
android:progress="2"
android:layout_marginTop="82dp"
android:max="3"
android:indeterminate="false"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true" />
above is my progress bar xml code.
Any help guys? :)
Thanks so much in advance! :)
If android version is 5.0 and above you just need to set
android:indeterminateTint="#color/BLACK"
android:indeterminateTintMode="src_in"
For lower version I use this
mProgressBar.getIndeterminateDrawable().setColorFilter(getResources()
.getColor(R.color.primary_color),PorterDuff.Mode.SRC_IN);
Create a new XML file in your drawable folder called something like custom_progress_bar.xml and paste this there:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="#android:id/background">
<clip>
<shape>
<solid android:color="#000000" />
</shape>
</clip>
</item>
<!-- Define the progress properties like start color, end color etc -->
<item android:id="#android:id/progress">
<clip>
<shape>
<solid android:color="#FFFFFF" />
</shape>
</clip>
</item>
</layer-list>
And in your <ProgressBar> add this attribute:
android:progressDrawable="#drawable/custom_progress_bar"
Change the 2 colors to your own preference. I put #FFFFFF and #000000 which are white and black.
Go to your styles.xml and change the colorAccent value from your base application theme e.g.
<item name="colorAccent">{COLOR}</item>
I am using minSdkVersion 15 and it worked for me.
If you want to change the ProgressBar color, not by drawable, you can use this style as theme for the ProgressBar
<style name="ProgressBar" parent="Widget.AppCompat.ProgressBar">
<item name="colorAccent">#color/white_primary</item>
</style>
If android:indeterminateTint doesn't work, try this:
<ProgressBar
android:id="#+id/progress_bar"
style="#android:style/Widget.ProgressBar.Horizontal"
android:progressTint="#color/Red" <--------------------------
android:progressBackgroundTint="#color/Blue" <---------------
android:layout_width="250sp"
android:layout_height="wrap_content"
android:progress="2"
android:layout_marginTop="82dp"
android:max="3"
android:indeterminate="false"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true" />
Try this and add you custom color
Progressbar mBar= (ProgressBar) findViewById(R.id.spinner);
mBar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#80DAEB"),
android.graphics.PorterDuff.Mode.MULTIPLY);
Hope this helps
For future references:
For API 21+ we can use directly in the XML:
android:indeterminateTint="#android:color/white"
set theme in style.xml like this
<style name="ProgressBar" parent="Widget.AppCompat.ProgressBar">
<item name="colorAccent">#color/dark_blue</item>
</style>
then use this style as "theme" in progressBar like this,
<ProgressBar
android:id="#+id/progressBar"
android:theme="#style/ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="440dp"
app:layout_constraintEnd_toEndOf="#+id/splashTitle"
app:layout_constraintHorizontal_bias="0.493"
app:layout_constraintStart_toStartOf="#+id/splashTitle"
app:layout_constraintTop_toBottomOf="#+id/splashTitle" />
Happy coding
Related
I want loading process exactly like this :
I try this :
<style name="CustomProgress" parent="Theme.AppCompat.Dialog">
<item name="android:windowBackground">#color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="colorAccent">#color/colorPrimary</item>
</style>
and
pDialog = new ProgressDialog(getContext(), R.style.CustomProgress);
but this is not exactly that i want!
Create circle drawable progress_background.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#BC000000" />
You can directly use the background on progress Bar itself . You can also do it with style.
<ProgressBar
android:indeterminateTint="#android:color/white"
android:indeterminateTintMode="src_in"
android:layout_width="wrap_content"
android:padding="4dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:background="#drawable/progress"
android:layout_height="wrap_content"/>
android:indeterminateTint is available on 21+. If your minimum SDK version is lower then it then you can change progress bar color with other way but you get the idea.
I've this issue, I don't know where it come from, I've created this buttons with custom background, but the background color talking the primary color and cannot change it unless change the primary color.
<Button
android:id="#+id/btn_teacher"
style="#style/normalText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/_16sdp"
android:background="#drawable/btn_rounded_stroke"
android:text="#string/txt_teacher" />
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="bg_color">#FFD7A4</color>
</resources>
I have many buttons with different colors, so i can't change the primary color
here is my drawable background
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<shape android:shape="rectangle" >
<size android:height="#dimen/_48sdp" />
<corners android:radius="#dimen/_24sdp" />
<stroke android:width="#dimen/_1sdp" android:color="#59CECE" />
<solid android:color="#android:color/white"/>
</shape>
</item>
</layer-list>
I'm using new material design by google
implementation "com.google.android.material:material:1.3.0-alpha02"
How can i override this color?
Since you are using a Theme.MaterialComponents.* your Button is replaced at runtime by a MaterialButton.
Currently the backgroundTint is still the default MaterialButton style.
It means that if you are using a custom android:background, you have to make sure to null out backgroundTint to avoid that the custom background doesn't get tinted with the attr/colorPrimary defined in your theme.
You have to add app:backgroundTint="#null":
<Button
app:backgroundTint="#null"
android:background="#drawable/.."
In any case you don't need a custom background (btn_rounded_stroke) in your case. You are just using a custom background only to define rounded corners. This feature is provided by default by the MaterialButton, then just use the cornerRadius attribute.
Use the standard MaterialButton:
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="48dp"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
app:strokeColor="#59CECE"
app:cornerRadius="24dp"
When Material theme is used then Button view is mapped to MaterialButtton.
There is one more way to setup the button background in this case.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar"
...
<item name="materialButtonStyle">#style/ColoredButton</item>
</style>
<style name="ColoredButton" parent="Widget.MaterialComponents.Button.TextButton">
<item name="backgroundTint">#color/customButtonColor</item>
</style>
What worked for me
First create btn_style in your styles.xml or themes.xml
<style name="btn_style" parent="Widget.MaterialComponents.Button">
<item name="backgroundTint">#null</item>
</style>
then in you layout apply the style and use the color or drawable that you want
<Button
android:id="#+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:background="#color/Red"
style="#style/btn_style"
android:text="Button"/>
Try this .
Your Button:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:layout_margin="5dp"
android:background="#drawable/round_btn"
android:padding="20dp"
android:text="My Text" />
Here is your round_btn drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#008577" />
<corners android:radius="20dp" />
</shape>
In your Gradle just replace this line
implementation "com.google.android.material:material:1.3.0-alpha02"
with this
implementation 'com.google.android.material:material:1.2.1'
All you need to do is simply go to your themes.xml file and change the style name to:
style name="Theme.AnimatedLogin"
parent="Theme.AppCompat.Light.NoActionBar"
in Light theme mode and to:
style name="Theme.AnimatedLogin"
parent="Theme.AppCompat.DayNight.NoActionBar"
in Dark theme mode in your theme.xml(night) file and then you can customize your button and change its colour.
this should be a very easy to customize style...
i want a horizontal progress bar that is slithly thick (or that i can customize the thickness) and the color matches the apps color
if i do
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="#id/textLoading"
android:layout_centerHorizontal="true"
android:indeterminate="true"
/>
the progress bar is horizontal and matches app visual identity... but is too thin... the person need glases to see it
if i do
<ProgressBar
android:id="#+id/progressBar"
style="android:Widget.ProgressBar.Horizontal"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="#id/textLoading"
android:layout_centerHorizontal="true"
android:indeterminate="true"
/>
the progress bar is good thickness but the color is a stupid yellow that matches nothing in this plannet
how can i customize individual parameters???
there are many ways to achieve what you need:
1- use android:scaleY="8" in your XML file
or from code
mProgressBar.setScaleY(3f);
2- style="#android:style/Widget.ProgressBar.Horizontal"
this will make you have Horizontal progress bar, so you can inherit it in styles and edit it as follows:
<style name="CustomProgressBarHorizontal" parent="android:Widget.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/custom_progress_bar_horizontal</item>
<item name="android:minHeight">10dp</item>
<item name="android:maxHeight">20dp</item>
</style>
Here is an example for a progress bar:
<ProgressBar
android:id="#+id/progressBar"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="20dp"
android:progressDrawable="#drawable/my_progressbar" />
and here is my_progressbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#android:id/background"
android:gravity="center_vertical|fill_horizontal">
<shape android:shape="rectangle">
<corners android:radius="10dp"/>
<size android:height="20dp"/>
<solid android:color="#color/blue"/>
</shape>
</item>
<item
android:id="#android:id/progress"
android:gravity="center_vertical|fill_horizontal">
<scale android:scaleWidth="100%">
<shape android:shape="rectangle">
<corners
android:radius="10dp"
/>
<size android:height="20dp"/>
<solid android:color="#color/yellow"/>
</shape>
</scale>
</item>
</layer-list>
Here is an example of how it looks:
You can use Android Material Progress Bar:
com.google.android.material.progressindicator.LinearProgressIndicator
XML example:
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="#+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="45"
app:indicatorColor="#color/blue_light"
app:trackColor="#FFFFFF"
app:trackCornerRadius="5dp"
app:trackThickness="10dp" />
Now you can use app:trackThickness to adjust the thickness of the progress bar
You can also check out Google's Material Design page regarding Material Progress Bar here: https://material.io/components/progress-indicators/android#using-progress-indicators
You can customize the style with:
<ProgressBar
android:id="#+id/progressBar"
android:indeterminate="true"
style="#style/CustomProgressBar"
with:
<style name="CustomProgressBar" parent="Widget.AppCompat.ProgressBar.Horizontal">
<item name="minHeight">32dip</item> <!-- default 16dp -->
<item name="maxHeight">32dip</item> <!-- default 16dp -->
</style>
If you want to customize the color use:
<ProgressBar
style="#style/CustomProgressBar"
android:indeterminate="true"
android:theme="#style/CustomProgressBarTheme"
/>
with:
<style name="CustomProgressBarTheme">
<item name="colorControlActivated">#color/....</item>
</style>
I'm trying to create an outlined Material Components button, however I need it to have a semi-transparent background in addition to the stroke.
This is my XML code so far:
<android.support.design.button.MaterialButton
android:id="#+id/foo"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:backgroundTint="#CFFF"
app:strokeColor="#color/colorAccent"
app:strokeWidth="2dp" />
And this is what this looks like:
The issue is that some of the background is visible outside the stroke around the button (the larger the stroke width, the more white pixels getting out).
For example, here's a 5dp stroke:
Is there a way to fix this, a better way to set the background color, or anything?
Just use the Widget.MaterialComponents.Button.OutlinedButton style:
<com.google.android.material.button.MaterialButton
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
app:strokeWidth="2dp"
app:strokeColor="#color/colorAccent"
app:backgroundTint="#3ad64f"
.../>
If you create a style of that you have to remove the app: In my example this style is called SecondButton
<style name="SecondButton" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="android:theme">#style/SecondButtonTheme</item>
<item name="backgroundTint">#color/second_button_back</item>
<item name="strokeColor">#color/second_button_text</item>
<item name="strokeWidth">1dp</item>
<item name="android:textColor">#color/second_button_text</item>
</style>
Use it like that in you
<com.google.android.material.button.MaterialButton
style="#style/SecondButton"
.../>
You could try to create your button in drawables directly in xlm based on this :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="backgroundcolor"/>
<stroke android:color="strokecolor" android:width="2dp" />
<!--corners allow us to make the rounded corners button-->
<corners android:radius="15dp" />
</shape>
</item>
</selector>
founded here : https://android--code.blogspot.fr/2015/01/android-rounded-corners-button.html
and use it like this in your layout :
android:background="#drawable/nameofbutton.xml"
I have a cardview. The button default color is grey. I want it to look like the right side image(like the blessings). This right one has been created setting backgroundtint to white but in older versions its still shows grey.
<android.support.v7.widget.CardView
android:id="#+id/programm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
android:layout_alignParentBottom="true"
android:layout_margin="6dp"
card_view:cardElevation="6dp"
android:layout_gravity="end|right"
card_view:cardBackgroundColor="#color/hotpink"
android:onClick="openNextActivity">
<Button
android:layout_width="wrap_content"
android:drawable="#color/white"
android:layout_height="wrap_content"
android:text="#string/Programme"
android:textColor="#color/hotpink"
android:onClick="openNextActivity"
/>
</android.support.v7.widget.CardView>
If i change the background of the button to white the entire color changes to white:
<android.support.v7.widget.CardView
android:id="#+id/programm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
android:layout_alignParentBottom="true"
android:layout_margin="6dp"
card_view:cardElevation="6dp"
android:layout_gravity="end|right"
card_view:cardBackgroundColor="#color/hotpink"
android:onClick="openNextActivity">
<Button
android:layout_width="wrap_content"
android:drawable="#color/white"
android:background="#color/white"
android:layout_height="wrap_content"
android:text="#string/Programme"
android:textColor="#color/hotpink"
android:onClick="openNextActivity"
/>
</android.support.v7.widget.CardView>
As per google search, this default grey color is set in some theme.I probably need to overwrite some theme and set some attribute. But I am not sure what do I need to change.
Try this:
<Button
android:layout_width="wrap_content"
android:text="Button Text"
android:theme="#style/myButtonTheme"
android:layout_height="wrap_content"/>
set this myButtonTheme in your styles.xml file:
<style name="myButtonTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColorPrimary">#color/white</item>
<item name="colorButtonNormal">#5552f1</item>
</style>
[ set your desired background color in colorButtonNormal ]
Output:
i haven't tested it for this kind of situation, but i think something like this can work
you can create a background.xml in your drawable directory and set it as background
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<item>
<shape>
<!-- set the shadow color here -->
<stroke
android:width="3dp"
android:color="#77000000" />
<!-- setting the thickness of shadow (positive value will give shadow on that side) -->
<padding
android:bottom="3dp"
android:left="1dp"
android:right="3dp"
android:top="1dp" />
<corners android:radius="4dp" />
</shape>
</item>
<!-- Background -->
<item>
<shape>
<solid android:color="#fff" />
<corners android:radius="4dp" />
</shape>
</item>
things you can try with this is that you can set the shadow color the color you want or something else that i had in mind was set the opacity of shadow color to zero so that it would be transparent and you can set its thickness by the paddings of the shadow
hope this helps
In yout styles define:
<style name="BlueButtonTheme" parent="#style/AppTheme">
<item name="android:buttonStyle">#style/Widget.AppCompat.Button.Colored</item>
<item name="colorButtonNormal">#color/disabledButtonColor</item>
<item name="colorAccent">#color/enabledButtonColor</item>
<item name="android:disabledAlpha">1</item>
<!-- button text color-->
<item name="android:textColor">#drawable/colored_button_text_color</item>
</style>
And in your layout xml file:
<Button
android:id="#+id/buttonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:theme="#style/BlueWhiteButtonTheme"
android:text="#string/buttonLabel"/>
Just set background for button in your layout
<Button
android:background="#android:color:white"
</Button>