android的引導頁庫:Introduction
介紹:
又一個引導頁庫
運行效果:

使用說明:
build.gradle:
dependencies { compile ('com.rubengees:introduction:1.0.5@aar'){ transitive = true; } }
如果不行,看看是否有一個新版本。如果沒有新版本并且還是不行,試試添加這個到build.gradle:
repositories { maven { url "http://dl.bintray.com/rubengees/maven" } }
Usage
如下創建一個IntroductionBuilder:
new IntroductionBuilder(this) //this is the Activity you want to start from.
添加一些Slide(頁面)到你的引導界面:
new IntroductionBuilder(this).withSlides(generateSlides())
private List<Slide> generateSlides() { List<Slide> result = new ArrayList<>(); result.add(new Slide().withTitle("Some title").withDescription("Some description"). withColorResource(R.color.green).withImage(R.drawable.myImage)); result.add(new Slide().withTitle("Another title").withDescription("Another description") .withColorResource(R.color.indigo).withImage(R.drawable.myImage2)); return result; }
最后介紹你自己
new IntroductionBuilder(this).withSlides(generateSlides()).introduceMyself();
這很簡單對吧?
你可以做很多自定義,下面講講解。
Options
你可以讓用戶決定,就要設置一樣。在silde中添加選項決定要顯示的元素:
new Slide().withTitle("Feature is doing something").withOption(new Option("Enable the feature")) .withColorResource(R.color.orange).withImage(R.drawable.image));
當用戶跑完了引導介紹,你會在onActivityResult中收到選中的Options。讀取結果:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == IntroductionBuilder.INTRODUCTION_REQUEST_CODE && resultCode == RESULT_OK) { String result = "User chose: "; for (Option option : data.<Option>getParcelableArrayListExtra(IntroductionActivity. OPTION_RESULT)) { result += option.getPosition() //The position of the Slide + (option.isActivated() ? " enabled" : " disabled"); } } }
使用 Gif作為圖片
本library支持GIF。就像普通drawable一樣添加就是了:
result.add(new Slide().withTitle("Some title").withDescription("Some description"). withColorResource(R.color.green).withImageResource(R.drawable.myGIF));
這將添加GIF,當導航到這個silde的時候gif會被自動播放。
Runtime Premissions
Android Marshmallow 引入了運行時權限,使用這個庫可以輕松請求。為此,你可以如下添加一個全局的listener:
new IntroductionBuilder(this).withSlides(slides) .withOnSlideChangedListener(new IntroductionConfiguration.OnSlideChangedListener() { @Override public void onSlideChanged(int from, int to) { if (from == 0 && to == 1) { if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 12); } } } }).introduceMyself();
你可以檢查是否授權,如下:
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == 12) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, "Permission was successfully granted!", Toast.LENGTH_LONG) .show(); } } }
風格
有兩種風格:Translucent 和 Fullscreen。要應用其中一種風格,如下:
new IntroductionBuilder(this).withSlides(generateSlides()) .withStyle(IntroductionBuilder.STYLE_FULLSCREEN).introduceMyself();
Translucent 是默認風格。
More
更多的解釋以及所有api可以在Wiki找到。
Minimum Sdk
The minimum required sdk is 10 (2.3.3 Gingerbread)
Libraries used in this project
-
android-gif-drawable For the GIFs.
-
SystemBarTint For the translucent style.
-
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!