正如我在标题中所写,我正在寻找一种在服务中显示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();
`
感谢您的帮助!
答案 0 :(得分:1)
答案 1 :(得分:0)
更新:我最终没有在我的服务中使用ShowcaseView Library,而是自己使用简单的TextView实现另一个演示。
我现在就是这样做的: 我只是在我要向用户介绍的按钮旁边显示一些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);
}
它的外观如下: (如果你想知道,文字是德文)