在这种情况下,我的Switch station应该以break或return x退出吗?
在我的应用程序中,用户可以选择一个文本,并使用图像上显示的选项设置其样式。在查看我的代码时,我想知道我的switch语句的cases语句是break
还是return true/false
以及它是否有任何影响?我可以通过使用Log.d();
看到break
退出switch方法,使用return
保持在switch方法中
那么在这种情况下,案例中发生了什么重要吗
开关盒的方法:
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.textcolor:
f3 = ColorPickerDialogFrag2.newInstance(3, Color.WHITE);
f3.setStyle(安卓.support.v4.app.DialogFragment.STYLE_NORMAL, R.style.AppTheme);
f3.show(fragmentManager, "d");
f3.setListener(this);
break;
//--------------------BOLD----------------------------
case R.id.bold:
styleSpans = str.getSpans(selectionStart, selectionEnd, StyleSpan.class);
for (int i = 0; i < styleSpans.length; i++) {
if (styleSpans[i].getStyle() == 安卓.graphics.Typeface.BOLD) {
str.removeSpan(styleSpans[i]);
exists = true;
}
}
if (!exists) {
str.setSpan(new StyleSpan(安卓.graphics.Typeface.BOLD), selectionStart, selectionEnd,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
editText.setSelection(selectionStart, selectionEnd);
return true;
//--------------------ITALIC----------------------------
case R.id.italic:
styleSpans = str.getSpans(selectionStart, selectionEnd, StyleSpan.class);
for (int i = 0; i < styleSpans.length; i++) {
if (styleSpans[i].getStyle() == 安卓.graphics.Typeface.ITALIC) {
str.removeSpan(styleSpans[i]);
exists = true;
}
}
if (!exists) {
str.setSpan(new StyleSpan(安卓.graphics.Typeface.ITALIC), selectionStart, selectionEnd,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
editText.setSelection(selectionStart, selectionEnd);
Log.d(LOG_TAG, "italic");
break;
//--------------------UNDERLINE----------------------------
case R.id.underline:
UnderlineSpan[] underSpan = str.getSpans(selectionStart, selectionEnd, UnderlineSpan.class);
for (int i = 0; i < underSpan.length; i++) {
str.removeSpan(underSpan[i]);
exists = true;
}
if (!exists) {
str.setSpan(new UnderlineSpan(), selectionStart, selectionEnd, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
editText.setSelection(selectionStart, selectionEnd);
Log.d(LOG_TAG, "underline");
return true;
//--------------------STROKE----------------------------
case R.id.stroke:
Log.d(LOG_TAG, "stroke");
安卓.text.style.StrikethroughSpan[] strokeSpan = str.getSpans(selectionStart, selectionEnd, 安卓.text.style.StrikethroughSpan.class);
for (int i = 0; i < strokeSpan.length; i++) {
str.removeSpan(strokeSpan[i]);
exists = true;
}
if (!exists) {
str.setSpan(new 安卓.text.style.StrikethroughSpan(), selectionStart, selectionEnd, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
editText.setSelection(selectionStart, selectionEnd);
return false;
case R.id.increase:
Log.d(LOG_TAG, "increase");
str.setSpan(new RelativeSizeSpan(1.1f), selectionStart, selectionEnd, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
editText.setSelection(selectionStart, selectionEnd);
break;
case R.id.decrease:
str.setSpan(new RelativeSizeSpan(0.9f), selectionStart, selectionEnd, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
editText.setSelection(selectionStart, selectionEnd);
break;
case 安卓.R.id.cut:
CharSequence charSequence = editText.getText().subSequence(selectionStart, selectionEnd);
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("simple text", charSequence);
clipboard.setPrimaryClip(clip);
editText.getText().replace(selectionStart, selectionEnd, "");
Toast.makeText(context, R.string.toastCopy, Toast.LENGTH_SHORT).show();
break;
case 安卓.R.id.copy:
charSequence = editText.getText().subSequence(selectionStart, selectionEnd);
clipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
clip = ClipData.newPlainText("simple text", charSequence);
clipboard.setPrimaryClip(clip);
Toast.makeText(context, R.string.toastCopy, Toast.LENGTH_SHORT).show();
break;
case R.id.textfont:
FontFragment fontFragment = new FontFragment(selectionStart, selectionEnd, editText);
fontFragment.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CustomDialog);
fontFragment.show(fragmentManager, "fontfragment");
break;
}
}
Log.d(LOG_TAG, "out of switch");
return true;
}
共 (0) 个答案