Last active
September 30, 2020 04:26
-
-
Save masaibar/ef7596eeae0e3ac272fa895c3b6dcffc to your computer and use it in GitHub Desktop.
いい感じのチュートリアル画面を5分で実装する ref: https://qiita.com/masaibar/items/f155cd1c7b6a795377f6
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
<activity | |
android:name=".TutorialActivity" | |
android:theme="@style/WelcomeScreenTheme"> |
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
compile 'com.stephentuso:welcome:1.4.1' | |
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
TitlePage(@DrawableRes int drawableResId, String title) |
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
BasicPage(@DrawableRes int drawableResId, String title, String description) |
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
ParallaxPage(@LayoutRes int layoutResId, String title, String description) |
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
FullscreenParallaxPage(@LayoutRes int layoutResId) |
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
@Override | |
protected WelcomeConfiguration configuration() { | |
return new WelcomeConfiguration.Builder(this) | |
... | |
.page(new FragmentWelcomePage() { | |
@Override | |
protected Fragment fragment() { | |
return new ExampleFragment(); | |
} | |
}.background(R.color.red_background)) | |
... | |
} |
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
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