当前位置: 首页 > 工具软件 > TapTargetView > 使用案例 >

引导图(TapTargetView)

蒯翰墨
2023-12-01

TapTargetView

用例一

TapTargetView.showFor(fragmentationSupportActivity, TapTarget.forView(homepageChildFragmentIvDailyCare, "this is a target", "We have the best targets, believe me.")
        // all options below are optional
        // specify a color for the outer circle
        .outerCircleColor(R.color.colorPrimary)
        // specify the alpha amount for the outer circle
        .outerCircleAlpha(0.7f)
        // specify a color for the target circle
        .targetCircleColor(R.color.background)
        // specify the size (in sp) of the title text
        .titleTextSize(20)
        // specify the color of the title text
        .titleTextColor(R.color.background)
        // specify the size (in sp) of the description text
        .descriptionTextSize(10)
        // specify the color of the description text
        .descriptionTextColor(R.color.red)
        // specify a color for both the title and description text
        .textColor(R.color.blue)
        // specify a typeface for the text
        .textTypeface(Typeface.SANS_SERIF)
        // If set, will dim behind the view with 30% opacity of the given color.
        .dimColor(android.R.color.black)
        // whether to draw a drop shadow or not
        .drawShadow(true)
        // whether tapping outside the outer circle dismisses the view
        .cancelable(false)
        // whether to tint the target view's color
        .tintTarget(false)
        // specify whether the target is transparent (displays the content underneath)
        .transparentTarget(false)
        .icon(ContextCompat.getDrawable(fragmentationSupportActivity, R.mipmap.ic_launcher))
        .targetRadius(60), new TapTargetView.Listener() {
    @Override
    public void onTargetClick(TapTargetView view) {
        super.onTargetClick(view);
        ToastUtils.shortShow(fragmentationSupportActivity, "onTargetClick");
    }
});

用例二

// We load a drawable and create a location to show a tap target here.
// We need the display to get the width and height at this point in time.
Display display = getActivity().getWindowManager().getDefaultDisplay();
// Load our little droid guy.
Drawable drawable = ContextCompat.getDrawable(fragmentationSupportActivity, R.drawable.ic_photo_library_24dp_yellow);
// Tell our droid buddy where we want him to appear.
Rect droidTarget = new Rect(0, 0, drawable.getIntrinsicWidth() * 2, drawable.getIntrinsicHeight() * 2);
// Using deprecated methods makes you look way cool.
droidTarget.offset(display.getWidth() / 2, display.getHeight() / 2);

// We have a sequence of targets, so lets build it!
TapTargetSequence sequence = new TapTargetSequence(fragmentationSupportActivity)
        .targets(
                // This tap target will target the back button, we just need to pass its containing toolbar.
                TapTarget.forToolbarNavigationIcon(homepageChildFragmentMt, "This is the back button.", "提示一").id(1),
                // Likewise, this tap target will target the search button.
                TapTarget.forToolbarMenuItem(homepageChildFragmentMt, R.id.notification, "This is a search icon.", "As you can see, it has gotten pretty dark around here...")
                        .dimColor(android.R.color.black)
                        .outerCircleColor(R.color.colorAccent)
                        .targetCircleColor(android.R.color.black)
                        .transparentTarget(true)
                        .textColor(android.R.color.black)
                        .id(2),
                // You can also target the overflow button in your toolbar.
                TapTarget.forToolbarOverflow(homepageChildFragmentMt, "This will show more options.", "But they're not useful :(").id(3),
                // This tap target will target our droid buddy at the given target rect.
                TapTarget.forBounds(droidTarget, "Oh look!", "You can point to any part of the screen. You also can't cancel this one!")
                        .cancelable(false)
                        .icon(drawable)
                        .id(4)
        )
        .listener(new TapTargetSequence.Listener() {
            // This listener will tell us when interesting(tm) events happen in regards
            // to the sequence
            @Override
            public void onSequenceFinish() {
                ToastUtils.shortShow(fragmentationSupportActivity, "onSequenceFinish");
            }

            @Override
            public void onSequenceStep(TapTarget lastTarget, boolean targetClicked) {
                Timber.d("Clicked on %s", lastTarget.id());
            }

            @Override
            public void onSequenceCanceled(TapTarget lastTarget) {
                AlertDialog dialog = new AlertDialog.Builder(fragmentationSupportActivity)
                        .setTitle("Uh oh")
                        .setMessage("You canceled the sequence")
                        .setPositiveButton("Oops", null).show();
                TapTargetView.showFor(dialog, TapTarget.forView(dialog.getButton(DialogInterface.BUTTON_POSITIVE), "Uh oh!", "You canceled the sequence at step " + lastTarget.id())
                        .cancelable(false)
                        .tintTarget(false), new TapTargetView.Listener() {
                    @Override
                    public void onTargetClick(TapTargetView view) {
                        super.onTargetClick(view);
                        dialog.dismiss();
                    }
                });
            }
        });
                
TapTargetView.showFor(fragmentationSupportActivity, TapTarget.forView(homepageChildFragmentMcvDailyCare, "Hello, world!", "哈哈")
        .cancelable(false)
        .drawShadow(true)
        .titleTextDimen(R.dimen.sp_16)
        .tintTarget(false), new TapTargetView.Listener() {
    @Override
    public void onTargetClick(TapTargetView view) {
        super.onTargetClick(view);
        // .. which evidently starts the sequence we defined earlier
        sequence.start();
    }

    @Override
    public void onOuterCircleClick(TapTargetView view) {
        super.onOuterCircleClick(view);
        ToastUtils.shortShow(getContext(), "You clicked the outer circle!");
    }

    @Override
    public void onTargetDismissed(TapTargetView view, boolean userInitiated) {
        Timber.d("You dismissed me :(");
    }
});
 类似资料: