(Unless mentioned otherwise, all of the following method calls should go in the Activity's onCreate().)
Slides:
material-intro has fluent style builders for both a simple text/image slide, as seen in Google's apps, and for slides featuring a custom Fragment or layout resource.
Feel free to submit an issue or pull request if you think any slide types are missing.
Base slide. If you want to modify what's shown in your slide this is the way to go.
Customization:
Left ("back") button:
Control left button behavior or hide/show it.
/* Show/hide button */setButtonBackVisible(true);
/* Use skip button behavior */setButtonBackFunction(BUTTON_BACK_FUNCTION_SKIP);
/* Use back button behavior */setButtonBackFunction(BUTTON_BACK_FUNCTION_BACK);
Right ("next") button:
Control right button behavior or hide/show it.
/* Show/hide button */setButtonNextVisible(true);
/* Use next and finish button behavior */setButtonNextFunction(BUTTON_NEXT_FUNCTION_NEXT_FINISH);
/* Use next button behavior */setButtonNextFunction(BUTTON_NEXT_FUNCTION_NEXT);
CTA button:
Change the appearance of the "call to action" button:
Make sure to call setFullscreen()before calling super.onCreate()
Scroll duration:
Adjust how long a single slide scroll takes.
setPageScrollDuration(500);
(The page scroll duration is dynamically adapted when scrolling more than one position to reflect dynamic durations from the Material design docs.
The exact formula for calculating the scroll duration is duration * (distance + sqrt(distance)) / 2.)
Navigation:
Block navigation:
There are three ways to block navigation for a slide:
For a SimpleSlide by setting SimpleSlide.Builder#canGoForward(boolean)/SimpleSlide.Builder#canGoBackward(boolean).
(If at least one permission is set to the SimpleSlide, navigation is automatically blocked until every permission is granted.)
Navigate through the intro manually using one of the following methods e.g. from a listeners callback.
Each of them will respect blocked navigation settings.
/* Scroll to any position */goToSlide(5);
/* Scroll to the next slide in the intro */nextSlide();
/* Scroll to the previous slide in the intro */previousSlide();
/* Scroll to the last slide of the intro */goToLastSlide();
/* Scroll to the first slide of the intro */goToFirstSlide();
Autoplay
Automatically scroll through the intro until user interacts with the intro.
/* Start an auto slideshow with 2500ms delay between scrolls and infinite repeats */autoplay(2500, INFINITE);
/* Start an auto slideshow with default configuration */autoplay();
/* Cancel the slideshow */cancelAutoplay()
Callbacks
If any of the above returns false when a user tries to navigate to a slide, a OnNavigationBlockedListener callback is fired that you can use to display a message. Additionally you can add plain-old ViewPager.OnPageChangeListeners to listen for page scrolls:
You can check if the user canceled the intro (by pressing back) or finished it including all slides.
Just call up the activity using startActivityForResult(intent, REQUEST_CODE_INTRO); and then listen for the result:
@OverrideprotectedvoidonActivityResult(intrequestCode, intresultCode, Intentdata) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_INTRO) {
if (resultCode == RESULT_OK) {
// Finished the intro
} else {
// Cancelled the intro. You can then e.g. finish this activity too.finish();
}
}
}
Parallax slides:
You can easily achieve a nice looking parallax effect for any slide by using either ParallaxFrameLayout.java, ParallaxLinearLayout.java or ParallaxRelativeLayout.java and defining layout_parallaxFactor for its direct childrens.
A higher factor means a stronger parallax effect, 0 means no parallax effect at all.
If you want to show the intro only at the first app start you can use onActivityResult() to store a shared preference when the user finished the intro.
See the demo app for a sample splash screen implementation:
MIT License
Copyright (c) 2017 Jan Heinrich Reimer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
请发表评论