fcannizzaro / material-tip
- четверг, 2 июня 2016 г. в 03:13:52
Java
Android Library for prompt tip
Android Library for prompt tip ( according to offer education )
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.fcannizzaro:material-tip:1.0.5'
}
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
...
app:layout_behavior="com.github.fcannizzaro.materialtip.TipBehavior"/>
...
<com.github.fcannizzaro.materialtip.MaterialTip
android:id="@+id/tip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
...
app:tip_background="color"
app:tip_color="color"
app:tip_text_color="color"
app:tip_title_color="color"
app:tip_icon="drawable"
app:tip_negative="string"
app:tip_positive="string"
app:tip_text="string"
app:tip_title="string"/>
</android.support.design.widget.CoordinatorLayout>
Attach the button listener
new ButtonListener() {
@Override
public void onPositive(MaterialTip tip) {
System.out.println("positive");
}
@Override
public void onNegative(MaterialTip tip) {
System.out.println("negative");
}
}
Set tip title
Set tip text
Set tip positive button text
Set tip negative button text
Set tip icon
Set tip primary color
Set tip background color
Set tip title color
Set tip text color
Each builder method is also available with Resources arg (ex. withTextRes, withTitleRes).
animate and show the tip
animate and hide the tip
animate and show/hide the tip
MaterialTip tip = (MaterialTip) findViewById(R.id.tip);
tip
.withTitle("Ok Google")
.withText("Something!")
.withPositive("save")
.withNegative("discard")
.withBackground(Color.parseColor("#363636"))
.withTextColor(Color.parseColor("#f5f5f5"))
.withTitleColor(Color.WHITE)
.setButtonListener(new ButtonListener() {
@Override
public void onPositive(MaterialTip tip) {
System.out.println("positive");
}
@Override
public void onNegative(MaterialTip tip) {
System.out.println("negative");
}
});
tip.show();
MIT - Francesco Cannizzaro