I want to have a ProgressBar with a static grey circle behind. Please check screenshot attached.
My current code looks like this:
main_layout.xml
<View
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:background="@drawable/progress_bar_background"
android:layout_marginBottom="-48dp" />
<ProgressBar
android:id="@+id/process_loading_circle"
style="?android:attr/progressBarStyle"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:indeterminateTint="@color/limeGreen" />
progress_bar_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android=";
android:shape="ring">
<solid android:color="@color/grey" />
<size android:width="48dp" android:height="48dp" />
<stroke android:thickness="4dp" android:thicknessRatio="2" />
</shape>
Just out of curiosity, I checked all of the shapes (line,ring,rectangle,oval) and it only works with oval and rectangle... ring is not being displayed at all.
I want to have a ProgressBar with a static grey circle behind. Please check screenshot attached.
My current code looks like this:
main_layout.xml
<View
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:background="@drawable/progress_bar_background"
android:layout_marginBottom="-48dp" />
<ProgressBar
android:id="@+id/process_loading_circle"
style="?android:attr/progressBarStyle"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:indeterminateTint="@color/limeGreen" />
progress_bar_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android/apk/res/android"
android:shape="ring">
<solid android:color="@color/grey" />
<size android:width="48dp" android:height="48dp" />
<stroke android:thickness="4dp" android:thicknessRatio="2" />
</shape>
Just out of curiosity, I checked all of the shapes (line,ring,rectangle,oval) and it only works with oval and rectangle... ring is not being displayed at all.
Share Improve this question asked Feb 17 at 14:38 AlexAlex 1,9366 gold badges25 silver badges41 bronze badges2 Answers
Reset to default 1Use CircularProgressIndicator from the material library:
<com.google.android.material.progressindicator.CircularProgressIndicator
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Configure the track color and thickness with trackColor
and trackThickness
attributes.
So my solution as @sdex wrote was to add the CircularProgressIndicator and my code looks like this
1)Create a style in themes.xml
<style name="CustomCircularProgressIndicator" parent="Widget.MaterialComponents.CircularProgressIndicator">
<item name="indicatorColor">@color/limeGreen</item>
<item name="trackColor">@color/grey</item>
</style>
2)Add MaterialComponents
to Base.Theme style
<style name="Base.Theme.YOURAPP" parent="Theme.MaterialComponents.DayNight.NoActionBar">
3)Lastly update your CircularProgressIndicator
<com.google.android.material.progressindicator.CircularProgressIndicator
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:indeterminate="true"
style="@style/CustomCircularProgressIndicator" />