本文整理了Java中android.widget.TextView.getSelectionEnd()
方法的一些代码示例,展示了TextView.getSelectionEnd()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.getSelectionEnd()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:getSelectionEnd
暂无
代码示例来源:origin: stackoverflow.com
TextView tv;
String stringYouExtracted = tv.getText().toString;
int startIndex = tv.getSelectionStart();
int endIndex = tv.getSelectionEnd();
stringYouExtracted = stringYouExtracted.subString(startIndex, endIndex);
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(stringYouExtracted);
代码示例来源:origin: andkulikov/Transitions-Everywhere
private void captureValues(TransitionValues transitionValues) {
if (transitionValues.view instanceof TextView) {
TextView textview = (TextView) transitionValues.view;
transitionValues.values.put(PROPNAME_TEXT, textview.getText());
if (textview instanceof EditText) {
transitionValues.values.put(PROPNAME_TEXT_SELECTION_START,
textview.getSelectionStart());
transitionValues.values.put(PROPNAME_TEXT_SELECTION_END,
textview.getSelectionEnd());
}
if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
transitionValues.values.put(PROPNAME_TEXT_COLOR, textview.getCurrentTextColor());
}
}
}
代码示例来源:origin: andkulikov/Transitions-Everywhere
private void captureValues(TransitionValues transitionValues) {
if (transitionValues.view instanceof TextView) {
TextView textview = (TextView) transitionValues.view;
transitionValues.values.put(PROPNAME_TEXT, textview.getText());
if (textview instanceof EditText) {
transitionValues.values.put(PROPNAME_TEXT_SELECTION_START,
textview.getSelectionStart());
transitionValues.values.put(PROPNAME_TEXT_SELECTION_END,
textview.getSelectionEnd());
}
if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
transitionValues.values.put(PROPNAME_TEXT_COLOR, textview.getCurrentTextColor());
}
}
}
代码示例来源:origin: square/assertj-android
public S hasSelectionEnd(int position) {
isNotNull();
int actualPosition = actual.getSelectionEnd();
assertThat(actualPosition) //
.overridingErrorMessage("Expected selection end <%s> but was <%s>.", position,
actualPosition) //
.isEqualTo(position);
return myself;
}
代码示例来源:origin: stackoverflow.com
.getText()
.subSequence(tv.getSelectionStart(),
tv.getSelectionEnd()).toString();
Log.d("tapped on:", s);
代码示例来源:origin: robolectric/robolectric
@Test
public void append_whenSelectionReachesToEnd_shouldExtendSelectionToTheEnd() throws Exception {
textView.setText("12", TextView.BufferType.EDITABLE);
Selection.setSelection(textView.getEditableText(), 0, 2);
textView.append("3");
assertEquals(3, textView.getSelectionEnd());
assertEquals(0, textView.getSelectionStart());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void append_whenSelectionIsAtTheEnd_shouldKeepSelectionAtTheEnd() throws Exception {
textView.setText("1", TextView.BufferType.EDITABLE);
Selection.setSelection(textView.getEditableText(), 0, 0);
textView.append("2");
assertEquals(0, textView.getSelectionEnd());
assertEquals(0, textView.getSelectionStart());
Selection.setSelection(textView.getEditableText(), 2, 2);
textView.append("3");
assertEquals(3, textView.getSelectionEnd());
assertEquals(3, textView.getSelectionStart());
}
代码示例来源:origin: stackoverflow.com
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
TextView tv = (TextView)v;
if(! (tv.getSelectionStart()==-1 && tv.getSelectionEnd()==-1))
// Fired only when you touch the part of the text that is hyperlinked
// do something
}
代码示例来源:origin: stackoverflow.com
TextView textView;
String stringToBeExtracted;
int startingIndex=textView.getSelectionStart();
int endingIndex=textView.getSelectionEnd();
stringToBeExtracted = stringYouExtracted.subString(startingIndex, endingIndex);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(stringToBeExtracted);
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Text Copied", stringToBeExtracted);
clipboard.setPrimaryClip(clip);
}
代码示例来源:origin: stackoverflow.com
TextView tv;
String stringYouExtracted = tv.getText().toString;
int startIndex = tv.getSelectionStart();
int endIndex = tv.getSelectionEnd();
stringYouExtracted = stringYouExtracted.subString(startIndex, endIndex);
代码示例来源:origin: stackoverflow.com
TextView txtview;
String stringSelected = txtview.getText().toString;
int startIndex = txtview.getSelectionStart();
int endIndex = txtview.getSelectionEnd();
stringSelected = stringSelected.subString(startIndex, endIndex);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clpbrd = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(stringSelected);
} else {
android.content.ClipboardManager clpbrd = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", stringSelected);
clipboard.setPrimaryClip(clip);
}
代码示例来源:origin: com.squareup.assertj/assertj-android
public S hasSelectionEnd(int position) {
isNotNull();
int actualPosition = actual.getSelectionEnd();
assertThat(actualPosition) //
.overridingErrorMessage("Expected selection end <%s> but was <%s>.", position,
actualPosition) //
.isEqualTo(position);
return myself;
}
代码示例来源:origin: stackoverflow.com
TextView tv;
String stringYouExtracted = tv.getText().toString;
int startIndex = tv.getSelectionStart();
int endIndex = tv.getSelectionEnd();
stringYouExtracted = stringYouExtracted.subString(startIndex, endIndex);
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(stringYouExtracted);
代码示例来源:origin: burgessjp/GetWordTextView
private void setSelectedSpan(TextView tv) {
if (mSelectedBackSpan == null || mSelectedForeSpan == null) {
mSelectedBackSpan = new BackgroundColorSpan(selectedColor);
mSelectedForeSpan = new ForegroundColorSpan(Color.WHITE);
} else {
mSpannableString.removeSpan(mSelectedBackSpan);
mSpannableString.removeSpan(mSelectedForeSpan);
}
mSpannableString.setSpan(mSelectedBackSpan, tv.getSelectionStart(), tv.getSelectionEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mSpannableString.setSpan(mSelectedForeSpan, tv.getSelectionStart(), tv.getSelectionEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
GetWordTextView.super.setText(mSpannableString, mBufferType);
}
代码示例来源:origin: burgessjp/GetWordTextView
@Override
public void onClick(View widget) {
TextView tv = (TextView) widget;
int startIndex = tv.getSelectionStart();
int endIndex = tv.getSelectionEnd();
if (TextUtils.isEmpty(getText()) || startIndex == -1 || endIndex == -1) {
return;
}
String word = tv
.getText()
.subSequence(startIndex,
endIndex).toString();
setSelectedSpan(tv);
if (mOnWordClickListener != null) {
mOnWordClickListener.onClick(word);
}
}
代码示例来源:origin: stackoverflow.com
text.setSpan(new StyleSpan(Typeface.BOLD),tv.getSelectionStart(),tv.getSelectionEnd(),0);
text.setSpan(new StyleSpan(Typeface.NORMAL),tv.getSelectionStart(),tv.getSelectionEnd(),0);
代码示例来源:origin: stackoverflow.com
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Log.e("", String.format("onActionItemClicked item=%s/%d", item.toString(), item.getItemId()));
CharacterStyle cs;
TextView bodyView = null;
int start = bodyView.getSelectionStart();
int end = bodyView.getSelectionEnd();
SpannableStringBuilder ssb = new SpannableStringBuilder(bodyView.getText());
/*Toast.makeText(getActivity(), (String)data.result,
Toast.LENGTH_LONG).show();*/
Toast.makeText(this, " toast shown ", Toast.LENGTH_LONG).show();
switch (item.getItemId()) {
case R.id.bold:
cs = new StyleSpan(Typeface.BOLD);
ssb.setSpan(cs, start, end, 1);
bodyView.setText(ssb);
return true;
case R.id.italic:
cs = new StyleSpan(Typeface.ITALIC);
ssb.setSpan(cs, start, end, 1);
bodyView.setText(ssb);
return true;
case R.id.underline:
cs = new UnderlineSpan();
ssb.setSpan(cs, start, end, 1);
bodyView.setText(ssb);
return true;
}
return false;
}
代码示例来源:origin: stackoverflow.com
TextView t1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1=(TextView) findViewById(R.id.textView1);
t1.setTextIsSelectable(true);// IMPORTANT
t1.setText("This is Android program");
t1.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_UP:
int start=t1.getSelectionStart();
int end=t1.getSelectionEnd();
String sub=t1.getText().subSequence(start, end).toString();
Toast.makeText(getBaseContext(), sub, 1).show();
}
return true;
}
});
}
代码示例来源:origin: geniusgithub/AndroidDialer
private int getEndPos(TextView widget) {
int end;
if (widget.getSelectionStart() == mManager.getSelectionStart()) {
end = widget.getSelectionEnd();
} else {
end = widget.getSelectionStart();
}
return end;
}
代码示例来源:origin: andforce/iBeebo
@Override
public void onClick(View v) {
// This condition will satisfy only when it is not an autolinked
// text
// onClick action
boolean isNotLink = layout.recontent.getSelectionStart() == -1 && layout.recontent.getSelectionEnd() == -1;
boolean isDeleted = msg.getRetweeted_status() == null || msg.getRetweeted_status().getUser() == null;
if (isNotLink && !isDeleted) {
startActivity(BrowserWeiboMsgActivity.newIntent(BeeboApplication.getInstance().getAccountBean(),
msg.getRetweeted_status(), BeeboApplication
.getInstance().getAccessTokenHack()));
} else if (isNotLink) {
Toast.makeText(getActivity(), getString(R.string.cant_open_deleted_weibo), Toast.LENGTH_SHORT).show();
}
}
};
内容来源于网络,如有侵权,请联系作者删除!