如何在Android中使用ShowcaseView瞄准ListView中的元素



我使用ShowcaseView瞄准了操作栏中的项目,但我不能瞄准ListView的元素!我试过了,但没有成功:

ShowcaseView sv = new ShowcaseView.Builder(this,true)
    .setTarget(new ViewTarget(lv.getChildAt(1).findViewById(R.id.heart)))
    // Here is where you supply the id of the action bar item you
    // want to display
    .setContentTitle("Heart")
    .setContentText("Check the venues of your city")
    .hideOnTouchOutside()
    .build();

非常简单。取ViewHolder中的元素,然后将显示ShowCaseView的代码放在bindView中。

不要忘记为列表中的每个元素添加不同的ID。

所以你可以尝试这样做。

public class ViewHolder extends RecyclerView.ViewHolder {
  private TextView button;
  public ViewHolder(final View itemView) {
    super(itemView);
    button = (Button) itemView.findViewById(R.id.list_button);
    button.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        new MaterialShowcaseView.Builder(getActivity())
          .setTarget(verifyButton)
          .setDismissText("GOT IT")
          .setContentText("Your text goes here")
          .setDelay(100) // optional but starting animations immediately in onCreate can make them choppy
          .singleUse(id + " define an unique id for each item of the list") // provide a unique ID used to ensure it is only shown once
          .show();
        }
      });
    }
  }
}

要获取更多信息,您可以查看这里的库

最新更新