Julian Julian - 1 month ago 13
Android Question

How to add text to a ProgressBar?

So this is my

ProgressBar
. Is it possible to write text "in" the bar? Thank you in advance!

<ProgressBar
android:id="@+id/kcal"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/makros"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@android:color/holo_green_light" />


edit: thank you for all the answers!

EKN EKN
Answer

You should try this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" android:layout_height="match_parent" >

    <ProgressBar
        android:id="@+id/myProgress"
        android:layout_width="match_parent" android:layout_height="match_parent" />



 <TextView
        android:id="@+id/myTextProgress"
        android:layout_alignLeft="@id/myProgress" android:layout_alignTop="@id/myProgress"
        android:layout_alignRight="@id/myProgress" android:layout_alignBottom="@id/myProgress"
        android:background="@android:color/transparent" >

</RelativeLayout>

You can add your text view in myTextProgress and it will display inside the progressbar

Comments