icon Material Tap Target Prompt GitHub

Follow the quick start guide below to get started.

FAB Example

JavaDocs, examples and a sample app with examples implemented are available. The sample app is available to download on the Google Play Store: Get it on Google Play

Quick start

Gradle

Add the following to build.gradle:

repositories {
    jcenter()
}

dependencies {
    implementation 'uk.co.samuelwall:material-tap-target-prompt:2.12.2'
}

Supports Android minSdkVersion 14

Usage

Tap target prompts are created with a builder class much like the Android AlertDialog builder:

builder = new MaterialTapTargetPrompt.Builder(MainActivity.this)

Set the view to focus the prompt on:

builder.setTarget(R.id.target_view_id)

Set the text to display on the first line:

builder.setPrimaryText("This text is displayed on the first line")

Optionally set the text to display on the second line. If the primary text is not set the secondary text must be set

builder.setSecondaryText("Text to display on the second line")

To listen in to the prompt events set a PromptStateChangeListener. Possible states are:

builder.setPromptStateChangeListener(new MaterialTapTargetPrompt.PromptStateChangeListener()
        {
            @Override
            public void onPromptStateChanged(MaterialTapTargetPrompt prompt, int state)
            {
                if (state == MaterialTapTargetPrompt.STATE_FOCAL_PRESSED)
                {
                    // User has pressed the prompt target
                }
            }
        })

The Builder extends abstract class PromptOptions which contains more customisation options.

Finally show the tap target:

builder.show()

All combined together:

import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;

new MaterialTapTargetPrompt.Builder(MainActivity.this)
        .setTarget(R.id.target_view_id)
        .setPrimaryText("This text is displayed on the first line")
        .setSecondaryText("Text to display on the second line")
        .setPromptStateChangeListener(new MaterialTapTargetPrompt.PromptStateChangeListener()
        {
            @Override
            public void onPromptStateChanged(MaterialTapTargetPrompt prompt, int state)
            {
                if (state == MaterialTapTargetPrompt.STATE_FOCAL_PRESSED)
                {
                    // User has pressed the prompt target
                }
            }
        })
        .show();

Note

If a target is not set or the target view could not be found or both the primary and secondary text are null then builder.show and builder.create will return null.

Customisation

The library is designed with extendable classes to allow for maximum customisation. More details and examples are available here.

License

Copyright (C) 2016-2018 Samuel Wall

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Edit this page