Skip to content

Instantly share code, notes, and snippets.

@creativedrewy
Last active July 24, 2019 21:28
Show Gist options
  • Save creativedrewy/f984acfa91421ae7aad8f4e478f5731d to your computer and use it in GitHub Desktop.
Save creativedrewy/f984acfa91421ae7aad8f4e478f5731d to your computer and use it in GitHub Desktop.
## 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