Last active
December 31, 2018 16:16
-
-
Save realpacific/7655cef3b9ff6685d473526fa9220ae7 to your computer and use it in GitHub Desktop.
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"?> | |
<RelativeLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/snackbar_relativelayout" | |
android:layout_width="match_parent" | |
android:layout_height="20dp" | |
android:alpha="0.6" | |
android:layout_gravity="center_horizontal" | |
android:background="@android:color/black"> | |
<TextView | |
android:id="@+id/snackbar_text" | |
android:layout_width="wrap_content" | |
android:layout_height="20dp" | |
android:gravity="center" | |
android:layout_centerInParent="true" | |
tools:text="No connection" | |
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" | |
android:textColor="@android:color/white"/> | |
</RelativeLayout> |
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
//.. | |
import com.google.android.material.snackbar.BaseTransientBottomBar | |
class CustomSnackbar private constructor( | |
parent: ViewGroup, content: View, | |
callback: com.google.android.material.snackbar.ContentViewCallback | |
) : BaseTransientBottomBar<CustomSnackbar>(parent, content, callback) { | |
fun setText(text: CharSequence): CustomSnackbar { | |
val textView = getView().findViewById<View>(R.id.snackbar_text) as TextView | |
textView.text = text | |
return this | |
} | |
/** | |
* content view inflation animation | |
*/ | |
private class CustomContentViewCallback(private val content: View) : | |
com.google.android.material.snackbar.ContentViewCallback { | |
override fun animateContentIn(delay: Int, duration: Int) { | |
} | |
override fun animateContentOut(delay: Int, duration: Int) { | |
// ObjectAnimator.ofFloat(content, View.SCALE_Y, 1f, 0f).setDuration(1000).start() | |
} | |
} | |
companion object { | |
fun make(parent: ViewGroup, duration: Int): CustomSnackbar { | |
val inflater = LayoutInflater.from(parent.context) | |
val content = inflater.inflate(R.layout.custom_snackbar, parent, false) | |
val viewCallback = CustomContentViewCallback(content) | |
return CustomSnackbar(parent, content, viewCallback).run { | |
getView().setPadding(0, 0, 0, 0) | |
this.duration = duration | |
this | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment