Skip to content

Instantly share code, notes, and snippets.

@Hackforid
Created August 15, 2016 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hackforid/f0d07e642f918429d221efc15e2e8f32 to your computer and use it in GitHub Desktop.
Save Hackforid/f0d07e642f918429d221efc15e2e8f32 to your computer and use it in GitHub Desktop.
Google Support Lib那些坑
/**
* 解决Snackbar只能使用RootView的问题 防止Fragment切换后Snackbar依旧显示
*/
fun makeSnackbar(parent: ViewParent, text: CharSequence, duration: Int) : Snackbar {
val constructor = Snackbar::class.java.getDeclaredConstructor(ViewGroup::class.java)
constructor.isAccessible = true
val snackbar = constructor.newInstance(parent)
snackbar.setText(text)
snackbar.duration = duration
return snackbar
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment