Last active
July 24, 2019 21:28
-
-
Save creativedrewy/f984acfa91421ae7aad8f4e478f5731d to your computer and use it in GitHub Desktop.
## Indeterminate Progress Bar on Android Preferences Screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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