Skip to content

Instantly share code, notes, and snippets.

@masaibar
Last active September 30, 2020 04:26
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 masaibar/ef7596eeae0e3ac272fa895c3b6dcffc to your computer and use it in GitHub Desktop.
Save masaibar/ef7596eeae0e3ac272fa895c3b6dcffc to your computer and use it in GitHub Desktop.
いい感じのチュートリアル画面を5分で実装する ref: https://qiita.com/masaibar/items/f155cd1c7b6a795377f6
<activity
android:name=".TutorialActivity"
android:theme="@style/WelcomeScreenTheme">
compile 'com.stephentuso:welcome:1.4.1'
TitlePage(@DrawableRes int drawableResId, String title)
BasicPage(@DrawableRes int drawableResId, String title, String description)
ParallaxPage(@LayoutRes int layoutResId, String title, String description)
FullscreenParallaxPage(@LayoutRes int layoutResId)
@Override
protected WelcomeConfiguration configuration() {
return new WelcomeConfiguration.Builder(this)
...
.page(new FragmentWelcomePage() {
@Override
protected Fragment fragment() {
return new ExampleFragment();
}
}.background(R.color.red_background))
...
}
class TutorialActivity : WelcomeActivity() {
companion object {
/**
* まだ表示していなかったらチュートリアルを表示
* SharedPreferencesの管理に関しては内部でよしなにやってくれているので普通に呼ぶだけで良い
*/
fun showIfNeeded(activity: Activity, savedInstanceState: Bundle?) {
WelcomeHelper(activity, TutorialActivity::class.java).show(savedInstanceState)
}
/**
* 強制的にチュートリアルを表示したい時にはこちらを呼ぶ
*/
fun showForcibly(activity: Activity) {
WelcomeHelper(activity, TutorialActivity::class.java).forceShow()
}
}
/**
* 表示するチュートリアル画面を定義する
*/
override fun configuration(): WelcomeConfiguration {
return WelcomeConfiguration.Builder(this)
.defaultBackgroundColor(BackgroundColor(Color.RED))
.page(TitlePage(R.mipmap.ic_launcher, "Title"))
.page(BasicPage(
android.R.drawable.ic_delete,
"Basic page 1",
"hogehoge")
.background(BackgroundColor(Color.GREEN)))
.page(BasicPage(
android.R.drawable.ic_btn_speak_now,
"Basic page 2",
"fugafuga")
.background(BackgroundColor(Color.BLUE))
)
.swipeToDismiss(true)
.build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment