本文整理匯總了Java中android.widget.TextView.getText方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.getText方法的具體用法?Java TextView.getText怎麽用?Java TextView.getText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getText方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createUnrestrictedLayout
import android.widget.TextView; //導入方法依賴的package包/類
private static Layout createUnrestrictedLayout(@Nonnull TextView view) {
CharSequence text = view.getText();
Layout layout = view.getLayout();
TextPaint paint = layout.getPaint();
if (SDK_INT >= M) {
return StaticLayout.Builder
.obtain(text, 0, text.length(), layout.getPaint(), layout.getWidth())
.setAlignment(layout.getAlignment())
.setLineSpacing(view.getLineSpacingExtra(), view.getLineSpacingMultiplier())
.setIncludePad(view.getIncludeFontPadding())
.setBreakStrategy(view.getBreakStrategy())
.setHyphenationFrequency(view.getHyphenationFrequency())
.build();
} else {
return new StaticLayout(
text,
paint,
text.length(),
layout.getAlignment(),
view.getLineSpacingMultiplier(),
view.getLineSpacingExtra(),
view.getIncludeFontPadding());
}
}
示例2: addGesture
import android.widget.TextView; //導入方法依賴的package包/類
@SuppressWarnings({"UnusedDeclaration"})
public void addGesture(View v) {
if (mGesture != null) {
final TextView input = (TextView) findViewById(R.id.gesture_name);
final CharSequence name = input.getText();
if (name.length() == 0) {
input.setError(getString(R.string.error_missing_name));
return;
}
final GestureLibrary store = GestureBuilderActivity.getStore();
store.addGesture(name.toString(), mGesture);
store.save();
setResult(RESULT_OK);
final String path = new File(Environment.getExternalStorageDirectory(),
"gestures").getAbsolutePath();
Toast.makeText(this, getString(R.string.save_success, path), Toast.LENGTH_LONG).show();
} else {
setResult(RESULT_CANCELED);
}
finish();
}
示例3: setThreadName
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Setting the thread name in the action bar.
* */
protected boolean setThreadName(TextView txtName){
String displayName = thread.displayName();
if (StringUtils.isBlank(displayName) )
return false;
if (txtName.getText() == null || !displayName.equals(txtName.getText().toString()))
{
// Set the title of the screen, This is used for the label in the screen overview on lollipop devices.
setTitle(displayName);
txtName.setText(displayName);
txtName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showToast(((TextView) v).getText().toString());
}
});
return true;
}
return false;
}
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:28,代碼來源:ChatSDKAbstractChatActivity.java
示例4: textTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 微博文本觸摸監聽處理
*
* @param textView 點擊的TextView
* @param event
* @return true:點擊事件被處理;false:點擊事件未被處理,向上冒泡
*/
private boolean textTouchEvent(TextView textView, MotionEvent event) {
boolean ret = false;
CharSequence text = textView.getText();
Spannable sText = Spannable.Factory.getInstance().newSpannable(text);
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= textView.getTotalPaddingLeft();
y -= textView.getTotalPaddingTop();
x += textView.getScrollX();
y += textView.getScrollY();
Layout layout = textView.getLayout();
int line = layout.getLineForVertical(y);
int offset = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] links = sText.getSpans(offset, offset, ClickableSpan.class);
if (links.length != 0) {
if (action == MotionEvent.ACTION_UP) {
links[0].onClick(textView);
}
ret = true;
}
}
return ret;
}
示例5: getString
import android.widget.TextView; //導入方法依賴的package包/類
/**獲取string,為null則返回""
* @param tv
* @return
*/
public static String getString(TextView tv) {
if (tv == null || tv.getText() == null) {
return "";
}
return getString(tv.getText().toString());
}
示例6: onClick
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public void onClick(View textView) {
TextView tv = (TextView) textView;
Spanned s = (Spanned) tv.getText();
int start = s.getSpanStart(this);
int end = s.getSpanEnd(this);
clickListener.onClick(type, s.subSequence(start, end).toString().trim());
}
示例7: getAccessibilityText
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public CharSequence getAccessibilityText() {
if (mView == null) return "";
TextView messageView = (TextView) mView.findViewById(R.id.infobar_message);
if (messageView == null) return "";
return messageView.getText() + mContext.getString(R.string.bottom_bar_screen_position);
}
示例8: extract
import android.widget.TextView; //導入方法依賴的package包/類
private static Object[] extract(@NonNull TextView view) {
final Object[] out;
final CharSequence text = view.getText();
if (!TextUtils.isEmpty(text) && text instanceof Spanned) {
out = ((Spanned) text).getSpans(0, text.length(), TableRowSpan.class);
} else {
out = null;
}
return out;
}
示例9: stripUnderlines
import android.widget.TextView; //導入方法依賴的package包/類
public static void stripUnderlines(TextView textView) {
Spannable s = new SpannableString(textView.getText());
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span: spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
s.removeSpan(span);
span = new URLSpanNoUnderline(span.getURL());
s.setSpan(span, start, end, 0);
}
textView.setText(s);
}
示例10: convert
import android.widget.TextView; //導入方法依賴的package包/類
@Override
protected void convert(final BaseViewHolder helper, final WaitMovieBean.DataBean.ComingBean item) {
helper.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ToastUtil.showShort(mContext, helper.getAdapterPosition() + "");
}
});
// 圖片地址不能直接使用,需要進行轉換
String originUrl = item.getImg();
String imgUrl = originUrl.replace("/w.h/", "/") + "@171w_240h_1e_1c_1l";//後綴為圖片大小
GlideManager.loadImage(mContext, imgUrl, (ImageView) helper.getView(R.id.iv_wait_movie));
helper.setText(R.id.tv_wait_movie_name, item.getNm())
.setText(R.id.tv_wait_movie_desc, item.getScm())
.setText(R.id.tv_wait_movie_wish, String.format("%s人想看", item.getWish()))
.setText(R.id.tv_wait_movie_major, String.format("主演:%s", item.getStar()));
TextView tv_wish = helper.getView(R.id.tv_wait_movie_wish);
Spannable spannable = new SpannableString(tv_wish.getText());
spannable.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.text_yellow, null)), 0, tv_wish.getText().toString().indexOf("人想看"), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv_wish.setText(spannable);
helper.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MovieDetailActivity.invoke(mContext, item.getId());
}
});
}
示例11: layoutDebugInfo
import android.widget.TextView; //導入方法依賴的package包/類
private void layoutDebugInfo(final int positionInStrip, final ViewGroup placerView,
final int x) {
final TextView debugInfoView = mDebugInfoViews.get(positionInStrip);
final CharSequence debugInfo = debugInfoView.getText();
if (debugInfo == null) {
return;
}
placerView.addView(debugInfoView);
debugInfoView.measure(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final int infoWidth = debugInfoView.getMeasuredWidth();
final int y = debugInfoView.getMeasuredHeight();
ViewLayoutUtils.placeViewAt(
debugInfoView, x - infoWidth, y, infoWidth, debugInfoView.getMeasuredHeight());
}
示例12: createShareIntent
import android.widget.TextView; //導入方法依賴的package包/類
private Intent createShareIntent() {
String msg = mRecipe.getName() + "\n" + "----\n" +
getString(R.string.ingredients_title) + ":\n" + "----\n";
for(TextView ingredient : mIngredientList){
msg += ingredient.getText() + "\n";
}
msg += getString(R.string.steps_title) + ":\n" + "----\n";
for(Step step : mStepList){
msg += step.getShortDescription() + "\n";
}
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, msg);
return shareIntent;
}
示例13: clickClickableSpan
import android.widget.TextView; //導入方法依賴的package包/類
public static ViewAction clickClickableSpan(final CharSequence textToClick) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return instanceOf(TextView.class);
}
@Override
public String getDescription() {
return "clicking on a ClickableSpan";
}
@Override
public void perform(UiController uiController, View view) {
TextView textView = (TextView) view;
SpannableString spannableString = (SpannableString) textView.getText();
if (spannableString.length() == 0) {
// TextView is empty, nothing to do
throw new NoMatchingViewException.Builder()
.includeViewHierarchy(true)
.withRootView(textView)
.build();
}
// Get the links inside the TextView and check if we find textToClick
ClickableSpan[] spans = spannableString.getSpans(0, spannableString.length(), ClickableSpan.class);
if (spans.length > 0) {
ClickableSpan spanCandidate;
for (ClickableSpan span : spans) {
spanCandidate = span;
int start = spannableString.getSpanStart(spanCandidate);
int end = spannableString.getSpanEnd(spanCandidate);
CharSequence sequence = spannableString.subSequence(start, end);
if (textToClick.toString().equals(sequence.toString())) {
span.onClick(textView);
return;
}
}
}
// textToClick not found in TextView
throw new NoMatchingViewException.Builder()
.includeViewHierarchy(true)
.withRootView(textView)
.build();
}
};
}
示例14: setColorSpanOnTextView
import android.widget.TextView; //導入方法依賴的package包/類
private void setColorSpanOnTextView(TextView view, String fulltext, String subtext, int color) {
view.setText(fulltext, TextView.BufferType.SPANNABLE);
Spannable str = (Spannable) view.getText();
int i = fulltext.indexOf(subtext);
str.setSpan(new ForegroundColorSpan(color), i, i + subtext.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
示例15: getHeaderText
import android.widget.TextView; //導入方法依賴的package包/類
public CharSequence getHeaderText() {
final TextView titleView = getHeaderTextView();
return titleView != null ? titleView.getText() : null;
}