gpt4 book ai didi

java - 在 ShowcaseViews 按钮上启动新 Intent

转载 作者:行者123 更新时间:2023-12-01 06:17:01 24 4
gpt4 key购买 nike

我想知道如果用户按下我的 Android 应用内教程 (ShowcaseViews) 中的按钮,如何启动新 Intent 。这是我的 ShowcaseViews 类:

public class ShowcaseViews {

private final List<ShowcaseView> views = new ArrayList<ShowcaseView>();
private final Activity activity;
private final int showcaseTemplateId;

private interface OnShowcaseAcknowledged {
void onShowCaseAcknowledged(ShowcaseView oldView);
}

/**
* @param activity The activity containing the views you wish to showcase
* @param showcaseTemplateLayout Must be the layout of a ShowcaseView - use this to style your showcase
*/
public ShowcaseViews(Activity activity, int showcaseTemplateLayout) {
this.activity = activity;
this.showcaseTemplateId = showcaseTemplateLayout;
}

public void addView(ItemViewProperties properties) {
ShowcaseView viewTemplate = newInstanceOfShowcaseView();
viewTemplate.setShowcaseItem(properties.itemType, properties.id, activity);
viewTemplate.setText(properties.titleResId, properties.messageResId);
setChainClickListener(viewTemplate);
views.add(viewTemplate);
}

public void addView(ViewProperties properties) {
ShowcaseView viewTemplate = newInstanceOfShowcaseView();
View v = activity.findViewById(properties.id);
viewTemplate.setShowcaseView(v);
viewTemplate.setText(properties.titleResId, properties.messageResId);
setChainClickListener(viewTemplate);
views.add(viewTemplate);
}

private ShowcaseView newInstanceOfShowcaseView() {
return (ShowcaseView) activity.getLayoutInflater().inflate(showcaseTemplateId, null);
}

private void setChainClickListener(final ShowcaseView viewTemplate) {
viewTemplate.overrideButtonClick(new View.OnClickListener() {
@Override
public void onClick(View v) {
acknowledgedListener.onShowCaseAcknowledged(viewTemplate);
}
});
}

private OnShowcaseAcknowledged acknowledgedListener = new OnShowcaseAcknowledged() {
@Override
public void onShowCaseAcknowledged(ShowcaseView oldView) {
oldView.hide();
show();
}
};

/**
* Showcases will be shown in the order they where added, continuing when the button is pressed
*/
public void show() {
if (views.isEmpty()) {
return;
}
final ShowcaseView view = views.get(0);
((ViewGroup) activity.getWindow().getDecorView()).addView(view);
views.remove(0);
}

/**
* Used for views on the ActionBar
*/
public static class ItemViewProperties extends ViewProperties {
public static final int ID_SPINNER = 0;
public static final int ID_TITLE = 0;
protected final int itemType;

public ItemViewProperties(int id, int titleResId, int messageResId, int itemType) {
super(id, titleResId, messageResId);
this.itemType = itemType;
}
}

/**
* Used for all views except those on the ActionBar
*/
public static class ViewProperties {
protected final int titleResId;
protected final int messageResId;
protected final int id;

public ViewProperties(int id, int titleResId, int messageResId) {
this.id = id;
this.titleResId = titleResId;
this.messageResId = messageResId;
}
}

}

这是我的 MainActivity 类:

 public void showcaseSecondActivity() {
ShowcaseViews views = new ShowcaseViews(CameraTestActivity.this, R.layout.view_showcase);
views.addView(new ShowcaseViews.ItemViewProperties(0, R.string.showcase_main_spinner_title, R.string.showcase_main_spinner_message, ShowcaseView.ITEM_ACTION_HOME));
Intent intent = new Intent(CameraTestActivity.this, UserSettingsActivity.class);
views.show();
}

这是我的 view_showcase XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<!-- This is our ShowCase template that we will use
whenever we want to showcase an item.
Here we can customise the colors of the showcase. -->
<com.rohit.ShowcaseView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:showcaseview="http://schemas.android.com/apk/res/com.rohit"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
showcaseview:sv_backgroundColor="@color/showcase_background"
showcaseview:sv_buttonText="@string/showcase_button_ok" />

如果我在 MainActivity 类中的 views.show() 之后添加 startActivity(intent),它甚至不会显示对话框并直接进入 Intent 。我想在用户单击按钮后打开 Activity 。我不知道要继续。我对此很陌生,我已经在 SO 和 Google 上进行了搜索。任何有关此问题的帮助将不胜感激。

最佳答案

showcaseView.setOnShowcaseEventListener(new OnShowcaseEventListener() {
@Override
public void onShowcaseViewShow(ShowcaseView arg0) { }

@Override
public void onShowcaseViewHide(ShowcaseView arg0) {
Intent i = new Intent(SignIn.this,MainFragmentActivity.class);
startActivity(i);
}

@Override
public void onShowcaseViewDidHide(ShowcaseView arg0) { }
});

关于java - 在 ShowcaseViews 按钮上启动新 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22340348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com