下面列出了android.view.View#OnClickListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private View.OnClickListener getMenuItemCLick(final int menuIndex, final int color) {
return new View.OnClickListener() {
@Override public void onClick(View v) {
if (menuIndex == curretMenuIndex) {
onBackPressed();
} else if (menuIndex == 0 && !(currentFragment instanceof WaterFragment)) {
((MenuAnimation) currentFragment).exitFromMenu();
WaterFragment waterFragment = new WaterFragment();
waterFragment.setIntroAnimate(true);
goToFragment(waterFragment);
hideMenu();
selectMenuItem(menuIndex, color);
} else if (menuIndex == 1 && !(currentFragment instanceof WindFragment)) {
((MenuAnimation) currentFragment).exitFromMenu();
WindFragment windFragment = new WindFragment();
windFragment.setIntroAnimate(true);
goToFragment(windFragment);
hideMenu();
selectMenuItem(menuIndex, color);
} else if (menuIndex == 2) {
startActivity(new Intent(RootActivity.this, PlayGroundActivity.class));
onBackPressed();
}
}
};
}
public void showFeatureSnackbar(final Activity activity, FloatingActionButton fab) {
if (!sharedPrefs.getBoolean(CUSTOM_THEMES_SNACKBAR, false)) {
View.OnClickListener oc = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(activity, NestedSettingsActivity.class);
intent.putExtra("key", "appearance");
activity.startActivityForResult(intent, 1);
}
};
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putBoolean(CUSTOM_THEMES_SNACKBAR, true);
editor.apply();
Snackbar.make(fab, R.string.snackbar_feature, Snackbar.LENGTH_LONG)
.setAction(R.string.snackbar_feature_oc, oc)
.show();
}
}
/**
* 设置toolbar最右侧按钮的图片,以及点击事件.
*
* @param toolbar toolbar
* @param resId 图片的resId
* @param onClickListener 点击事件监听
*/
protected void setActionImageView(Toolbar toolbar, @DrawableRes int resId, View.OnClickListener onClickListener) {
View actionView = ButterKnife.findById(toolbar, R.id.actionView);
ImageView actionImageView = ButterKnife.findById(toolbar, R.id.actionImageView);
if (actionImageView != null) {
actionView.setVisibility(View.VISIBLE);
actionImageView.setImageResource(resId);
actionView.setOnClickListener(onClickListener);
}
}
protected final void showHamburger(boolean show, @Nullable View.OnClickListener listener) {
if (show) {
ibToolbarHamburger.setVisibility(View.VISIBLE);
ibToolbarHamburger.setOnClickListener(listener);
} else {
ibToolbarHamburger.setVisibility(View.INVISIBLE);
}
}
private View.OnClickListener getChangeFolderListener() {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mFolderDialog == null) {
mFolderDialog = new FolderDialog(getActivity(), mData);
mFolderDialog.setOnFolderSelectedListener(SelectorFragment.this);
}
mFolderDialog.show();
}
};
}
/**
* 设置监听器
*
* @param l 监听器
* @param ids view 的 id
*/
public void setOnClickListener(View.OnClickListener l, int... ids) {
if (ids == null) {
return;
}
for (int id : ids) {
get(id).setOnClickListener(l);
}
}
protected View getEmptyView(final int layout, final int msg,
final int button, final View.OnClickListener listener) {
final View view = LayoutInflater.from(context).inflate(layout, null);
final CocoQuery nq = new CocoQuery(view);
nq.id(R.id.empty_msg).text(msg);
nq.id(R.id.empty_button).text(button).clicked(listener);
return view;
}
private View getFooterView(int type, View.OnClickListener listener) {
View view = getLayoutInflater().inflate(R.layout.footer_view, mRecyclerView, false);
if (type == 1) {
ImageView imageView = view.findViewById(R.id.iv);
imageView.setImageResource(R.mipmap.rm_icon);
}
view.setOnClickListener(listener);
return view;
}
public void showSnackBar(@StringRes int stringResId, boolean showLong, @StringRes int actionResId, View.OnClickListener listener) {
Snackbar.make(_activity.findViewById(android.R.id.content), stringResId,
showLong ? Snackbar.LENGTH_LONG : Snackbar.LENGTH_SHORT)
.setAction(actionResId, listener)
.show();
}
public ItemViewHolder(Context mContext, ViewGroup parent, View.OnClickListener mListener) {
super(UIUtil.infalte(mContext, R.layout.holder_item, parent));
textView = ButterKnife.findById(itemView, R.id.tv_item);
this.mListener = mListener;
}
@Nullable
public View.OnClickListener value() {
return value_OnClickListener;
}
public View.OnClickListener getOnClickListener() {
return onClickListener;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
TextView textView = findViewById(R.id.text);
textView.setMovementMethod(new LinkMovementMethod());
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(view.getContext(), "Clicked", Toast.LENGTH_LONG).show();
}
};
Drawable drawable = getResources().getDrawable(R.drawable.ic_android_16dp);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth() * 2, drawable.getIntrinsicHeight() * 2);
// @formatter:off
Spannable spannable = new Spanner()
.append("Original text\n\n")
.append("Big and blurry\n", Spans.sizePX(100))
.span("blurry", blur(5.0f, BlurMaskFilter.Blur.SOLID))
.append("big in DP\n", sizeDP(30))
.append("50% of original size\n", scaleSize(0.5f))
.append("bold\n", bold())
.append("italic\n", italic())
.append("bold and italic\n", boldItalic())
.append("custom typeface\n", font("sans-serif-black"))
.append("strike through\n", strikeThrough())
.append("underline\n", underline())
.append("background\n", background(Color.YELLOW))
.append("foreground\n", foreground(Color.RED))
.append("subscript\n", subscript())
.append("superscript\n", superscript())
.append("Image with custom bounds: ").append(image(drawable)).append("\n")
.append("Image from resources: ").append(image(this, R.drawable.ic_android_16dp)).append("\n")
.append("quite\n", quote())
.append("The quick brown fox jumps over the lazy dog\n", bold(), foreground(0xFF904f1c), Spans.quote())
.span("fox", foreground(Color.RED))
.span("dog", foreground(Color.RED))
.append("First occurrence, Second occurrence\n")
.span(292,"occurrence",background(Color.GREEN))
.append("Custom\n", custom(new CustomSpan()))
.append("Click here\n", click(onClickListener))
.append("http://www.android.com\n", url("http://www.android.com"))
;
// @formatter:on
textView.setText(spannable);
}
public static < T extends View > T mapClick(final Activity activity, final int id, final View.OnClickListener fn) {
final T v = find(activity, id);
if (v != null)
v.setOnClickListener(fn);
return v;
}
public NavigationDefaults navigationIconListener(View.OnClickListener listener) {
this.navigationIconListener = listener == null ? DUMMY_NAV_ICON_LISTENER : listener;
return this;
}
public TutoShowcase onClickContentView(@IdRes int viewId, View.OnClickListener onClickListener) {
return tutoShowcase.onClickContentView(viewId, onClickListener);
}
public void setOnAcceptButtonClickListener(
View.OnClickListener onAcceptButtonClickListener) {
this.onAcceptButtonClickListener = onAcceptButtonClickListener;
if(buttonAccept != null)
buttonAccept.setOnClickListener(onAcceptButtonClickListener);
}
public PeriodDialog setNegativeListener(View.OnClickListener listener) {
this.negativeListener = listener;
return this;
}
public void setMenuTogglerListener(View.OnClickListener menuTogglerListener) {
mMenuTogglerListener = menuTogglerListener;
}
/**
* 展示一个仅有一个按钮的对话框 仿iOS中间弹出
*
* @param activity 必须为activity
* @param msg 提示的内容
* @param bt_msg 按钮的文字
* @param onClickListener 点击事件监听
*/
public static void showOnlyOneButtonAlertDialog(Activity activity, String msg, String bt_msg, View.OnClickListener onClickListener) {
new AlertDialog(activity).builder().setMsg(msg)
.setNegativeButton(bt_msg, onClickListener).show();
}