Loading progress bar like Telegram - android

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.

Related

how to change android progress bar thickness

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>

Changing the color of ProgressBar not working in API<21

I am trying the change the color of the indeterminate progress bar using styles. Added the following changes
in values/styles-v21
<style name="CustomHorizontalProgress" >
<item name="android:indeterminateTint">#FF00FF</item>
<item name="android:indeterminateTintMode">src_in</item>
</style>
and in values/styles
<style name="CustomHorizontalProgress" >
<item name="colorAccent">#FF00FF</item>
</style>
and set these styles in progressbar as below
<ProgressBar
android:id="#+id/progress"
style="#style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:theme="#style/CustomHorizontalProgress"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:indeterminate="true"/>
For api>=21 everything this is working fine but colorAccent is not set as progress bar color in pre lollipop devices.
Note: I wanted to achieve this only using style.
Test it
<style name="CustomHorizontalProgress" parent="android:Widget.ProgressBar.Horizontal" >
<item name="android:indeterminateTint">#FF00FF</item>
<item name="android:indeterminateTintMode">src_in</item>
<style name="CustomHorizontalProgress" parent="android:Widget.ProgressBar.Horizontal">
<item name="colorAccent">#FF00FF</item></style>
layout xml
<ProgressBar
android:id="#+id/progress"
style="#style/CustomHorizontalProgress"
android:theme="#style/CustomHorizontalProgress"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:indeterminate="true"/>
</style>
progress.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);

How to change progress bar progress color?

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

How to have Material design buttons with different colors in API 21?

Coming from this thread: Android Material Design Button Styles
I couldn't understand how to individually change the colors of the buttons, so that not all buttons are with the same color.
<item name="android:colorButtonNormal">#color/blue</item>
This solution works nice, but it changes the color of all buttons.
In API 22, we can change the color of the different buttons by using the backgroundTint, like so:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="3dp"
android:backgroundTint="#color/orange"
android:text="#string/button1_text"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="18sp" />
How can we do it in API 21 ?
That's the styles.xml that I have:
<style name="AppTheme" parent="#android:style/Theme.Material.Light">
<item name="android:actionBarStyle">#style/actionBarCustomization</item>
<item name="android:spinnerDropDownItemStyle">#style/mySpinnerDropDownItemStyle</item>
<item name="android:spinnerItemStyle">#style/mySpinnerItemStyle</item>
<item name="android:colorButtonNormal">#color/myDarkBlue</item>
</style>
<style name="actionBarCustomization" parent="#android:style/Widget.Material.Light.ActionBar">
<item name="android:background">#color/white</item>
<item name="android:titleTextStyle">#style/actionBarTextColor</item>
</style>
<style name="actionBarTextColor" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/black</item>
</style>
Okay, I figured it out. Here is the way I solved it, I hope it helps someone else too (I am not saying that it's perfect).
I created a drawable material_ripple_effect.xml that looks like that:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/black">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp" />
<solid android:color="#color/myOrange" />
</shape>
</item>
</ripple>
And then in the layout, where I have the button, I just set the ripple drawable as a background. In activity_main.xml:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="3dp"
android:backgroundTint="#color/orange"
android:background="#drawable/material_ripple_effect"
android:text="#string/button1_text"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="18sp" />

Changing spinner arrow, Appcompat v21

i have activities which i themed with my custom theme, but for spinner i choosed to style it with Appcompat v21 but i got this :
So how to change the Spinner arrow to be black or blue if is there a way ?
i found this as similar question but doesn't have any answer : https://stackoverflow.com/questions/28561105/add-custom-spinner-arrow
here is my spinner :
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner2"
android:layout_marginTop="10dp"
android:layout_centerInParent="true" />
i used this to style the spinner:
<style name="MyTheme.SpinnerAppTheme" parent="Widget.AppCompat.Spinner">
</style>
this is how i use the adapter
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
getBaseContext(), R.array.listMedRes, android.R.layout.simple_spinner_item);
i just want to theme the spinner , thanks alot
Might be late but better late than never. To respond to your question: "Is there a way to use it only in spinner?". The answer is yes, refer to the code below.
Add this code to your theme or style file
<style name="customSpinnerTheme" parent="yourAppThemeThatUseAppCompat21">
<item name="colorControlNormal">#eaeaea</item>
<item name="colorControlActivated">#000000</item>
<item name="colorControlHighlight">#000000</item>
</style>
Then in your XML that use spinner you can add this line
android:theme="#style/customSpinnerTheme"
e.g.
<Spinner
android:theme="#style/customSpinnerTheme"
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:spinnerMode="dialog" />
Since you are using AppCompat-v21, you can take advantage of the new material design styles attributes:
colorPrimary: your app branding color for the app bar, applies to action bar
colorPrimaryDark: darker variant for the status bar and contextual app bars
colorAccent: lets you define bright complement to the primary branding color. By default, this is the color applied to framework controls (via colorControlActivated)
colorControlNormal: color applied to framework controls in their normal state
colorControlActivated: applied to framework controls in their activated
Here is an example for you
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/primary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- colorAccent is used as the default value for colorControlActivated which is used to tint widgets -->
<item name="colorAccent">#color/accent</item>
<item name="colorControlNormal">#color/primary</item>
</style>
colors.xml
<resources>
<color name="primary">#ff0000ff</color>
<color name="primary_dark">#ff0000af</color>
<color name="accent">#870000ff</color>
<color name="white">#ffffffff</color>
</resources>
Here is how it looks
Hope this helps.
There is a way to change your arrow color... actually it's not color you can change this image with blue color image..
create a xml file myspinner_selector in your drawable folder
and paste
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><layer-list>
<item><shape>
<gradient android:angle="90" android:endColor="#ffffff" android:startColor="#ffffff" android:type="linear" />
<stroke android:width="1dp" android:color="#504a4b" />
<corners android:radius="5dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape></item>
<item ><bitmap android:gravity="bottom|right" android:src="#drawable/blue_arrow" /> // you can use any other image here, instead of default_holo_dark_am
</item>
</layer-list></item>
</selector>
blue_arrow is an image, and add this style in your style file
<style name="spinner_style" >
<item name="android:background">#drawable/myspinner_selector</item>
<item name="android:layout_marginLeft">5dp</item>
<item name="android:layout_marginRight">5dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:paddingLeft">5dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
</style>
finally add this style in your spinner
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/spinner_style"
/>
it look like this. you need to customize
look at below code.
create spinner_bg.xml under drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><layer-list>
<item><shape>
<gradient android:angle="270" android:centerColor="#d0d0d0" android:endColor="#c5c6c6" android:startColor="#dbdadb" android:type="linear" />
<stroke android:width="1dp" android:color="#7a7a7a" />
<corners android:radius="1dp" />
<padding android:left="3dp" android:right="3dp" />
</shape></item>
<item><bitmap android:gravity="center|right" android:src="#drawable/dropdown_icon_black" />
</item>
</layer-list></item>
</selector>
write down below code in styles.xml
<style name="spinner_style">
<item name="android:background">#drawable/spinner_bg</item>
</style>
Apply style to spinner
<Spinner
android:id="#+id/spinner"
style="#style/spinner_style"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:focusable="true"
android:overlapAnchor="false"
android:paddingRight="10dp"
android:spinnerMode="dropdown"
android:textColor="#android:color/white" />
use this image for spinner drawable
you could tint it with the attribute tint color.
<Spinner android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:backgroundTint="#color/white"
/>

Categories

Resources