Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a number inside a progress spinner

Tags:

java

android

I have a progress spinner displayed in the menu. I'd like to display a number inside the spinner, how would I go about doing this? Below are some of the code snippets for what I am doing to make the progress spinner work:

public void onCreateOptionsMenu(...) {
    ...
    if (uploadCount > 0) {
        MenuItem updatingMenuItem = menu.findItem(R.id.photo_capture_action_updating);
        updatingMenuItem.setActionView(R.layout.action_progressbar);
        updatingMenuItem.expandActionView();
    } else {
        menu.removeItem(R.id.photo_capture_action_updating);
    }
}

And below is the action_progressbar.xml

<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">         
</ProgressBar>

Thank You,

like image 272
Gary Kipnis Avatar asked Dec 10 '25 19:12

Gary Kipnis


1 Answers

You can add a textview along with this progressbar,with gravity center and wrap it inside a frame layout. xml-

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/progressBarLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ProgressBar>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="14" />
</FrameLayout>

Hope this solves your problem.

like image 121
nikvs Avatar answered Dec 12 '25 08:12

nikvs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!