本文整理了Java中android.widget.TextView.length()
方法的一些代码示例,展示了TextView.length()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.length()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:length
暂无
代码示例来源:origin: hidroh/materialistic
@Override
public void onReceivedTitle(WebView view, String title) {
if (mTitleEditText.length() == 0) {
mTitleEditText.setText(title);
}
}
});
代码示例来源:origin: hidroh/materialistic
private boolean validate() {
mTitleLayout.setErrorEnabled(false);
mContentLayout.setErrorEnabled(false);
if (mTitleEditText.length() == 0) {
mTitleLayout.setError(getString(R.string.title_required));
}
if (mContentEditText.length() == 0) {
mContentLayout.setError(getString(R.string.url_text_required));
}
return mTitleEditText.length() > 0 && mContentEditText.length() > 0;
}
代码示例来源:origin: square/assertj-android
public S hasLength(int length) {
isNotNull();
int actualLength = actual.length();
assertThat(actualLength) //
.overridingErrorMessage("Expected length <%s> but was <%s>.", length, actualLength) //
.isEqualTo(length);
return myself;
}
代码示例来源:origin: hidroh/materialistic
@Override
protected void bind(SubmissionViewHolder holder, final Item item) {
super.bind(holder, item);
holder.mPostedTextView.setText(item.getDisplayedTime(mContext));
holder.mPostedTextView.append(item.getDisplayedAuthor(mContext,
!TextUtils.equals(item.getBy(), mUsername), 0));
holder.mMoreButton.setVisibility(View.GONE);
if (TextUtils.equals(item.getType(), Item.COMMENT_TYPE)) {
holder.mTitleTextView.setText(null);
holder.itemView.setOnClickListener(null);
holder.mCommentButton.setVisibility(View.GONE);
} else {
holder.mTitleTextView.setText(item.getDisplayedTitle());
holder.mCommentButton.setVisibility(View.VISIBLE);
holder.mCommentButton.setOnClickListener(v -> openItem(item));
}
holder.mTitleTextView.setVisibility(holder.mTitleTextView.length() > 0 ?
View.VISIBLE : View.GONE);
holder.mContentTextView.setVisibility(holder.mContentTextView.length() > 0 ?
View.VISIBLE : View.GONE);
if (!mExpanded.contains(item.getId()) && item.getParentItem() != null) {
mExpanded.add(item.getId());
new Handler().post(() -> {
mItems.add(0, item.getParentItem()); // recursive
notifyItemInserted(0);
notifyItemRangeChanged(1, mItems.size());
});
}
}
代码示例来源:origin: hidroh/materialistic
holder.mCommentButton.setText(R.string.view_story);
holder.mTitleTextView.setVisibility(holder.mTitleTextView.length() > 0 ?
View.VISIBLE : View.GONE);
holder.mContentTextView.setVisibility(holder.mContentTextView.length() > 0 ?
View.VISIBLE : View.GONE);
holder.mCommentButton.setVisibility(item.isDeleted() ? View.GONE : View.VISIBLE);
代码示例来源:origin: chiuki/advanced-textview
private void appendText(CharSequence text, Layout.Alignment align) {
if (text == null || text.toString().trim().length() == 0) {
return;
}
AlignmentSpan span = new AlignmentSpan.Standard(align);
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(span, 0, text.length(), 0);
if (textView.length() > 0) {
textView.append("\n\n");
}
textView.append(spannableString);
}
代码示例来源:origin: Ilhasoft/data-binding-validator
@Override
public boolean isValid(TextView view) {
return view.length() <= value;
}
代码示例来源:origin: Ilhasoft/data-binding-validator
@Override
public boolean isValid(TextView view) {
return view.length() >= value;
}
代码示例来源:origin: TinkoffCreditSystems/decoro
private void setSelection(int position) {
if (textView instanceof EditText && position <= textView.length()) {
((EditText) textView).setSelection(position);
}
}
}
代码示例来源:origin: sorz/TinyKeePass
private void showTextViewOnlyIfNotEmpty(TextView view) {
view.setVisibility(view.length() == 0 ? View.GONE : View.VISIBLE);
}
代码示例来源:origin: pmbento/karmadetector
private void addToLog(String content) {
final int LOG_MAX_BUFFER = 2000;
// lame log rotation implementation
if (textViewLog.length() > LOG_MAX_BUFFER)
textViewLog.setText(textViewLog.getText().toString().substring(100, textViewLog.length()));
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
textViewLog.append(currentDateTimeString + ": " + content + "\n");
}
代码示例来源:origin: com.squareup.assertj/assertj-android
public S hasLength(int length) {
isNotNull();
int actualLength = actual.length();
assertThat(actualLength) //
.overridingErrorMessage("Expected length <%s> but was <%s>.", length, actualLength) //
.isEqualTo(length);
return myself;
}
代码示例来源:origin: stackoverflow.com
TextView myTextView = (TextView) findViewById(R.id.my_text_view);
myTextView .setText("$29,500", TextView.BufferType.SPANNABLE);
final StrikethroughSpan STRIKE_THROUGH_SPAN = new StrikethroughSpan();
Spannable spannable = (Spannable) myTextView.getText();
spannable.setSpan(STRIKE_THROUGH_SPAN, 0, myTextView.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
myTextView.setText(spannable);
代码示例来源:origin: AnandChowdhary/saga-android
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE) {
if (textView.length() > 0) {
mClearButton.setVisibility(View.GONE);
mSearchProgress.setVisibility(View.VISIBLE);
getSearchResults(textView.getText().toString());
} else {
Toast.makeText(getApplicationContext(), getString(R.string.enter_song), Toast.LENGTH_SHORT).show();
}
return true;
}
return false;
}
});
代码示例来源:origin: stackoverflow.com
paintText.getTextBounds(text, 0, textView.length(), boundsText);
paintText.setTextAlign(Align.CENTER);
代码示例来源:origin: percolate/mentions
/**
* Highlights all the {@link Mentionable}s in the test {@link Comment}.
*/
private void highlightMentions(final TextView commentTextView, final List<Mentionable> mentions) {
if(commentTextView != null && mentions != null && !mentions.isEmpty()) {
final Spannable spannable = new SpannableString(commentTextView.getText());
for (Mentionable mention: mentions) {
if (mention != null) {
final int start = mention.getMentionOffset();
final int end = start + mention.getMentionLength();
if (commentTextView.length() >= end) {
spannable.setSpan(new ForegroundColorSpan(orange), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
commentTextView.setText(spannable, TextView.BufferType.SPANNABLE);
} else {
//Something went wrong. The expected text that we're trying to highlight does not
// match the actual text at that position.
Log.w("Mentions Sample", "Mention lost. [" + mention + "]");
}
}
}
}
}
代码示例来源:origin: onionApps/Chat.onion
void update() {
Tor tor = Tor.getInstance(getContext());
setVisibility(!tor.isReady() ? View.VISIBLE : View.GONE);
String status = tor.getStatus();
int i = status.indexOf(']');
if (i >= 0) status = status.substring(i + 1);
status = status.trim();
TextView view = (TextView) findViewById(R.id.status);
String prefix = "Bootstrapped";
if (status.contains("%") && status.length() > prefix.length() && status.startsWith(prefix)) {
status = status.substring(prefix.length());
status = status.trim();
view.setText(status);
} else if (view.length() == 0) {
view.setText("Starting...");
}
}
代码示例来源:origin: stackoverflow.com
public class LinkTransformationMethod implements TransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
Linkify.addLinks(textView, Linkify.WEB_URLS);
String stringText = textView.getText().toString();
Spannable text = (Spannable) textView.getText();
URLSpan[] spans = text.getSpans(0, textView.length(), URLSpan.class);
for (int i = spans.length - 1; i >= 0; i--) {
URLSpan oldSpan = spans[i];
text.removeSpan(oldSpan);
String url = oldSpan.getURL();
int startIndex = stringText.indexOf(url);
int lastIndex = startIndex + url.length();
text.setSpan(new CustomTabsURLSpan(url), startIndex, lastIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return text;
}
return source;
}
@Override
public void onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction, Rect previouslyFocusedRect) {
}
}
代码示例来源:origin: stackoverflow.com
// make "dolor" (characters 12 to 17) display a toast message when touched
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View view) {
TextView textView = (TextView) view;
CharSequence charSequence = textView.getText();
if (charSequence instanceof Spannable) {
Spannable spannableText = (Spannable)charSequence;
ClickableSpan[] spans = spannableText.getSpans(0, textView.length(), ClickableSpan.class);
for (ClickableSpan span : spans) {
int start = spannableText.getSpanStart(span);
int end = spannableText.getSpanEnd(span);
Toast.makeText(MainActivity.this, charSequence.subSequence(start, end), Toast.LENGTH_LONG).show();
}
}
}
};
代码示例来源:origin: MCMrARM/revolution-irc
public void applySelectionTo(View view, int position) {
TextView textView = findTextViewIn(view);
if (textView == null)
return;
int selStartIndex = ((AdapterInterface) mRecyclerView.getAdapter())
.getItemPosition(mSelectionStartId);
int selEndIndex = ((AdapterInterface) mRecyclerView.getAdapter())
.getItemPosition(mSelectionEndId);
if (position >= selStartIndex && position <= selEndIndex) {
if (selStartIndex == selEndIndex)
TextSelectionHelper.setSelection(textView.getContext(),
(Spannable) textView.getText(), mSelectionStartOffset, mSelectionEndOffset);
else if (position == selStartIndex)
TextSelectionHelper.setSelection(textView.getContext(),
(Spannable) textView.getText(), mSelectionStartOffset, textView.length());
else if (position == selEndIndex)
TextSelectionHelper.setSelection(textView.getContext(),
(Spannable) textView.getText(), 0, mSelectionEndOffset);
else
TextSelectionHelper.setSelection(textView.getContext(),
(Spannable) textView.getText(), 0, textView.length());
} else {
TextSelectionHelper.removeSelection((Spannable) textView.getText());
}
}
内容来源于网络,如有侵权,请联系作者删除!