Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在服务中使用ShowcaseView库或类似工具?_Java_Android_Service_Floating - Fatal编程技术网

Java 如何在服务中使用ShowcaseView库或类似工具?

Java 如何在服务中使用ShowcaseView库或类似工具?,java,android,service,floating,Java,Android,Service,Floating,正如我在标题中所写的,我正在寻找一种在服务中显示的方法。该服务显示了一个浮动的小部件,比如facebook messenger聊天头。问题是,“MaterialShowcaseView.Builder(this)”要求一个“android.app.Activity”属性 // single example new MaterialShowcaseView.Builder(this) .setTarget(mButtonShow)

正如我在标题中所写的,我正在寻找一种在服务中显示的方法。该服务显示了一个浮动的小部件,比如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();
`

谢谢你的帮助

我想我应该帮助你


您可以找到有关如何使用该库的指南。

更新:我最终没有在我的服务中使用,并使用简单的文本视图实现了另一个演示

我现在就是这样做的: 我只是在我想介绍给用户的按钮旁边显示一些文本视图。这不像ShowcaseView,但它对我来说非常适合

在浮动服务中创建文本视图: (我将XML文件中的TextView设置为“不可见”,并在初始化为“消失”之后设置为“不可见”)

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

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


你能解释更多吗?我不明白你有什么问题?你想在服务中演示吗?!你是说像facebook messenger聊天头这样的浮动小部件吗?你也可以在服务中获得上下文。。服务和活动都是从上下文类派生的。@ChintanSoni是的,完全是一个浮动小部件,就像facebook messenger聊天头一样。@Fakher是的,我想在服务中进行演示,但我认为这实际上是不可能的,因为库需要一些上下文形式的活动。我编辑了这个问题。谢谢,但我已经实现了类似的功能。我只想与它一起使用ShowcaseView。如果可能的话,请分享如何使用创建Showcase view的代码service@ShaileshLimbadiya我只是在我想向用户介绍的元素旁边的正确位置显示一些文本视图。我将更新我的帖子,并肯定会添加一些示例代码;)
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);
}