1 | initial version |
To show a spinner on an Android Studio background image, follow these steps:
Add a ProgressBar widget in your layout XML file where you want to show the spinner. For example:
<RelativeLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/background_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/background_image" />
<ProgressBar
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
In your activity or fragment, find the spinner widget using its ID and call its setVisibility
method to show or hide the spinner. For example:
ProgressBar spinner = findViewById(R.id.spinner);
spinner.setVisibility(View.VISIBLE); // Show spinner
spinner.setVisibility(View.GONE); // Hide spinner
You can also customize the spinner using its style attributes. For example, you can change its size and color by adding these attributes to the ProgressBar widget:
<ProgressBar
android:id="@+id/spinner"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_centerInParent="true"
android:indeterminateTint="@color/spinner_color"
android:indeterminateTintMode="src_in"
android:style="?android:attr/progressBarStyleLarge" />
Here, android:indeterminateTint
and android:indeterminateTintMode
set the spinner color, and android:style
sets the spinner size and style.