【问题标题】:How to use the ShowcaseView library or something similar in a service?如何在服务中使用 ShowcaseView 库或类似的东西?
【发布时间】:2016-03-11 11:09:45
【问题描述】:

正如我在标题中所写,我正在寻找一种在服务中显示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();

`

感谢您的帮助!

【问题讨论】:

  • 你能解释更多吗?我不明白你有什么问题?你想在服务中做演示?!
  • 你说的是像 facebook messenger 聊天头这样的浮动小部件吗?
  • 你也可以在服务中获取上下文。服务和活动都是从上下文类派生的。
  • @ChintanSoni 是的,就像 facebook messenger 聊天头一样的浮动小部件。
  • @Fakher 是的,我想在服务中进行演示,但我认为这实际上是不可能的,因为库需要一些上下文形式的活动。我编辑了问题。

标签: java android service floating


【解决方案1】:

我认为Tooleap 应该可以帮到你。

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

【讨论】:

  • 谢谢,但我已经实现了类似的东西。我只想和它一起使用 ShowcaseView。
【解决方案2】:

更新:我最终没有在我的服务中使用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);
}

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

【讨论】:

  • 如果可能,请分享如何使用服务创建展示案例视图的代码
  • @ShaileshLimbadiya 我只是在我想向用户介绍的元素旁边的正确位置显示一些 TextView。我会更新我的帖子,并肯定会添加一些示例代码;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-04
  • 2020-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-02
  • 1970-01-01
相关资源
最近更新 更多