如何在服务中使用 ShowcaseView 库或类似的东西?

How to use the ShowcaseView library or something similar in a service?

正如我在标题中所写,我正在寻找一种在服务中显示 ShowcaseView Library 的方法。该服务正在显示一个浮动小部件,如 facebook Messenger 聊天头。问题是,"MaterialShowcaseView.Builder(this)" 要求 "android.app.Activity" 属性。

// single example
        new MaterialShowcaseView.Builder(this)
                .setTarget(mButtonShow)
                .setDismissText("GOT IT")
                .setContentText("This is some amazing feature you should know about")
                .setDelay(withDelay) // optional but starting animations immediately in onCreate can make them choppy
                .singleUse(SHOWCASE_ID) // provide a unique ID used to ensure it is only shown once
                .show();

`

感谢您的帮助!

我觉得Tooleap应该能帮到你。

Here 您可以找到与如何使用库相关的指南。

更新: 我最终没有在我的服务中使用 ShowcaseView Library,我自己用简单的 TextViews 实现了另一个演示。

我现在是这样做的: 我只是在要向用户介绍的按钮旁边显示一些 TextView。这与 ShowcaseView 不同,但它非常适合我。

在浮动服务中创建 TextView: (我将XML文件中的TextView设置为"INVISIBLE",然后初始化为"GONE")

LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

exampleTextLayout = (LinearLayout) inflater.inflate(R.layout.exampleTextLayout, null);
exampleTextView= (TextView) exampleTextLayout.findViewById(R.id.exampleTextView);

WindowManager.LayoutParams textViewParam = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                PixelFormat.TRANSLUCENT);
        textViewParam.gravity = Gravity.TOP | Gravity.START;

windowManager.addView(exampleTextLayout, textViewParam);
exampleTextLayout.setVisibility(View.GONE);

然后当我想显示文本时,我会这样做: (我跳过了动画部分)

WindowManager.LayoutParams param_txt = (WindowManager.LayoutParams) layoutView.getLayoutParams();

param_txt.x = [xPosition of TextView]
param_txt.y = [yPosition of TextView]

if(layoutView.isAttachedToWindow()) {
      exampleTextLayout.setVisibility(View.VISIBLE);
      windowManager.updateViewLayout(exampleTextLayout, param_txt);
}

这是它的样子: (如果您想知道,文字是德语)