Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
## Indeterminate Progress Bar on Android Preferences Screen
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminateOnly="true"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" />
package com.your.package.structure.here
/**
* Custom Preference that provides an indeterminate progress bar for showing loading/long-running operations.
* Set checked to to "true" to show the progress bar and "false" to hide it.
*/
class LoadingPreferenceRow constructor(
context: Context, attrs: AttributeSet? = null
): SwitchPreference(context, attrs) {
init {
layoutResource = R.layout.item_loading_pref_row
}
override fun onBindViewHolder(holder: PreferenceViewHolder?) {
super.onBindViewHolder(holder)
val progressBar = holder?.itemView as? ProgressBar
progressBar?.visibility = if (isChecked) View.VISIBLE else View.GONE
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.