4 |
5 |
6 |
7 |
Try out sample application on Android PlayStore
12 | 13 | # Usage 14 | 15 | For a working implementation of this project see the /app folder 16 |Include the library as local library project or add this dependency in your build.gradle.
19 |
20 |
21 | dependencies {
22 | compile 'com.outlander.showcaseview:showcaseview:1.3.0'
23 | }
24 |
25 |
26 | Initialise the ShowcaseViewBuilder as follows:
29 |
30 |
31 | ShowcaseViewBuilder showcaseViewBuilder;
32 | ...
33 | showcaseViewBuilder = ShowcaseViewBuilder.init(this)
34 | .setTargetView(fab)
35 | .setBackgroundOverlayColor(0xdd4d4d4d)
36 | .setRingColor(0xcc8e8e8e)
37 | .setRingWidth((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()))
38 | .setMarkerDrawable(getResources().getDrawable(R.drawable.arrow_up), Gravity.LEFT)
39 | .addCustomView(R.layout.description_view, Gravity.TOP)
40 | .addCustomView(R.layout.skip_layout)
41 | .setCustomViewMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 70, getResources().getDisplayMetrics()));
42 |
43 | showcaseViewBuilder.show();
44 |
45 |
46 | Register click listeners on the customView added as follows:
49 |
50 |
51 | showcaseViewBuilder.setClickListenerOnView(R.id.exit_btn, new View.OnClickListener() {
52 | @Override
53 | public void onClick(View v) {
54 | //TODO: Add thing to do when clicked.
55 | }
56 | });
57 |
58 |
59 | To hide the showcaseView just call:
62 |
63 |
64 | showcaseViewBuilder.hide()
65 |
66 |
67 | To hide the showcaseView when user clicks on the overlay, just set the following flag: showcaseViewBuilder.setHideOnTouchOutside(true); By default, this is always false.
Call the showcaseViewBuilder.show() only after adding all the customViews and MarkerDrawable.
setRingWidth(float width) and other margin setters take pixels as parameters. So make sure to send into density independent pixels (dp) value to support multiple screen sizes (See the sample code snippet above for reference)
Once showcaseViewBuilder.hide() is called, all the click listeners get deregistered.
83 | Thus, you will have to set them back if showing it again. Better to register all the click listeners in a single method which can be called when showing the showcaseView.
setTargetView(View v): Sets the view which needs to be showcased.
setBackgroundOverlayColor(int color): Sets the color of the overlay to be shown.
setRingColor(int color): Sets the color of the ring around the showcaseView.
setRingWidth(float width): Sets the width of the ring around the showcaseView. Default value is 10px
setMarkerDrawable(Drawable drawable, int gravity): Sets the marker drawable if any to point the showcaseView. Also, sets a gravity for the drawable (TOP, LEFT, RIGHT, BOTTOM) around the showcasing view.
setDrawableLeftMargin(float margin): Sets the marker drawable left margin.
setDrawableTopMargin(float margin): Sets the marker drawable top margin.
addCustomView(View view, int gravity): Sets the custom description view to describe the showcaseView. Also, sets a gravity for the view (TOP, LEFT, RIGHT, BOTTOM) around the showcasing view.
addCustomView(View view): Sets the custom description view to describe the showcaseView. This doesn't takes any gravity as an argument and renders the view as per the gravity defined in the layout file.
setCustomViewMargin(int margin): Sets the custom description view margin from the showcaseView in the direction of the gravity defined, if any. If no gravity defined, then no point in using this method.
setHideOnTouchOutside(boolean hide): Sets the flag which decide whether to hide the showcase overlay when user touches on the screen anywhere.
setClickListenerOnView(int id, View.OnClickListener clickListener): Sets clicklistener on the components of the customView(s) added.
show(): Start showcasing the targetView.
hide(): Stop showcasing the targetView.