本文整理匯總了Java中android.widget.TextView.getContext方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.getContext方法的具體用法?Java TextView.getContext怎麽用?Java TextView.getContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getContext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dealAILink
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 解析機器人對話link
*
* @param textView
*/
private static void dealAILink(TextView textView, String type) {
CharSequence charSequence = textView.getText();
if (charSequence instanceof Spannable) {
textView.setText("");
Spannable s = (Spannable) charSequence;
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
String clickContent = s.subSequence(start, end).toString();
AIURLSpan myURLSpan = new AIURLSpan(span.getURL(), type, clickContent, textView.getContext());
s.setSpan(myURLSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
textView.append(s);
}
}
示例2: dealCustomLink
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 解析富文本link
*
* @param textView
*/
private static void dealCustomLink(TextView textView) {
CharSequence charSequence = textView.getText();
if (charSequence instanceof Spannable) {
textView.setText("");
Spannable s = (Spannable) charSequence;
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
CustomClickSpan myURLSpan = new CustomClickSpan(textView.getContext(), span.getURL());
s.setSpan(myURLSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
textView.append(s);
}
}
示例3: activityIsAlive
import android.widget.TextView; //導入方法依賴的package包/類
private boolean activityIsAlive() {
TextView textView = textViewWeakReference.get();
if (textView == null) {
return false;
}
Context context = textView.getContext();
if (context == null) {
return false;
}
if (context instanceof TintContextWrapper) {
context = ((TintContextWrapper) context).getBaseContext();
}
if (context instanceof Activity) {
if (((Activity) context).isFinishing()) {
return false;
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && ((Activity) context).isDestroyed()) {
return false;
}
}
}
return true;
}
示例4: setText
import android.widget.TextView; //導入方法依賴的package包/類
/** 顯示文本和表情 */
public static void setText(TextView textView, String text) {
Context context = textView.getContext();
Resources resources = context.getResources();
SpannableString ss = new SpannableString(text);
// 正則表達式: [高興]
Pattern p = Pattern.compile("\\[([A-Za-z\u4E00-\u9FA5]+)\\]");
Matcher matcher = p.matcher(ss);
while (matcher.find()) {
// 匹配到一個表情字符串
String emoji = matcher.group();
// 過濾非表情符,比如: [xxx]
if (EMOJI_DATAS.containsKey(emoji)) { // 是表情才處理
// System.out.println("----------" + emoji);
// 指定了一張圖片
Bitmap bitmap = BitmapFactory.decodeResource(resources, EMOJI_DATAS.get(emoji));
bitmap = Global.createBitmap(bitmap, Global.dp2px(20)); // 圖片的寬高為20dp
ImageSpan span = new ImageSpan(context, bitmap, ImageSpan.ALIGN_BOTTOM);
int start = matcher.start();
int end = matcher.end();
ss.setSpan(span, start, end, 0);
}
}
textView.setText(ss);
}
示例5: AutofitHelper
import android.widget.TextView; //導入方法依賴的package包/類
private AutofitHelper(TextView view) {
final Context context = view.getContext();
float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
mTextView = view;
mPaint = new TextPaint();
setRawTextSize(view.getTextSize());
mMaxLines = getMaxLines(view);
mMinTextSize = scaledDensity * DEFAULT_MIN_TEXT_SIZE;
mMaxTextSize = mTextSize;
mPrecision = DEFAULT_PRECISION;
}
示例6: create
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Creates a new instance of {@code AutofitHelper} that wraps a {@link TextView} and enables
* automatically sizing the text to fit.
*/
public static AutofitHelper create(TextView view, AttributeSet attrs, int defStyle) {
AutofitHelper helper = new AutofitHelper(view);
boolean sizeToFit = true;
if (attrs != null) {
Context context = view.getContext();
int minTextSize = (int) helper.getMinTextSize();
float precision = helper.getPrecision();
TypedArray ta = context.obtainStyledAttributes(
attrs,
R.styleable.AutofitTextView,
defStyle,
0);
sizeToFit = ta.getBoolean(R.styleable.AutofitTextView_sizeToFit, sizeToFit);
minTextSize = ta.getDimensionPixelSize(R.styleable.AutofitTextView_minTextSize,
minTextSize);
precision = ta.getFloat(R.styleable.AutofitTextView_precision, precision);
ta.recycle();
helper.setMinTextSize(TypedValue.COMPLEX_UNIT_PX, minTextSize)
.setPrecision(precision);
}
helper.setEnabled(sizeToFit);
return helper;
}
示例7: create
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Creates a new instance of {@code AutofitHelper} that wraps a {@link TextView} and enables
* automatically sizing the text to fit.
*/
public static AutofitHelper create(TextView view, AttributeSet attrs, int defStyle) {
AutofitHelper helper = new AutofitHelper(view);
boolean sizeToFit = true;
if (attrs != null) {
Context context = view.getContext();
int minTextSize = (int) helper.getMinTextSize();
float precision = helper.getPrecision();
TypedArray ta = context.obtainStyledAttributes(
attrs,
R.styleable.AutofitTextView,
defStyle,
0);
sizeToFit = ta.getBoolean(R.styleable.AutofitTextView_sizeToFit, sizeToFit);
minTextSize = ta.getDimensionPixelSize(R.styleable.AutofitTextView_minTextSize,
minTextSize);
precision = ta.getFloat(R.styleable.AutofitTextView_precision, precision);
ta.recycle();
helper.setMinTextSize(TypedValue.COMPLEX_UNIT_PX, minTextSize)
.setPrecision(precision);
}
helper.setEnabled(sizeToFit);
return helper;
}
示例8: adjustTextSize
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 使文字大小適應frame
*
* @param view
*/
public static void adjustTextSize(TextView view) {
final Context context = view.getContext();
float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
TextPaint paint = new TextPaint();
int maxLines = getMaxLines(view);
float minTextSize = scaledDensity * DEFAULT_MIN_TEXT_SIZE;
float maxTextSize = view.getTextSize();
float precision = DEFAULT_PRECISION;
adjustTextSize(view, paint, minTextSize, maxTextSize, maxLines, precision);
}
示例9: onInitialized
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public void onInitialized() {
final TextView regularTextView = mRegularTextViewRef.get();
if (regularTextView != null) {
final EmojiCompat compat = EmojiCompat.get();
final Context context = regularTextView.getContext();
regularTextView.setText(
compat.process(context.getString(R.string.regular_text_view, EMOJI)));
}
}
示例10: setTextSize
import android.widget.TextView; //導入方法依賴的package包/類
public static void setTextSize(TextView textview, String strdimen) {
if (textview == null || StringUtils.isEmpty(strdimen)) {
throw new IllegalArgumentException("Illegal argument to setTextSize()!");
}
Context context = textview.getContext();
int tvTitleSize = context.getResources().getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_title_txt_size"));
textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTitleSize);
}
示例11: setTextColor
import android.widget.TextView; //導入方法依賴的package包/類
public static void setTextColor(TextView textview, String colorid) {
if (textview == null || StringUtils.isEmpty(colorid)) {
throw new IllegalArgumentException("Illegal argument to setTextColor()!");
}
Context context = textview.getContext();
textview.setTextColor(context.getResources().getColor(ResHelper.getColorRes(context, colorid)));
}
示例12: autofit
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
*/
private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
int maxLines, float precision) {
if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
// Don't auto-size since there's no limit on lines.
return;
}
int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (targetWidth <= 0) {
return;
}
CharSequence text = view.getText();
TransformationMethod method = view.getTransformationMethod();
if (method != null) {
text = method.getTransformation(text, view);
}
Context context = view.getContext();
Resources r = Resources.getSystem();
DisplayMetrics displayMetrics;
float size = maxTextSize;
float high = size;
float low = 0;
if (context != null) {
r = context.getResources();
}
displayMetrics = r.getDisplayMetrics();
paint.set(view.getPaint());
paint.setTextSize(size);
if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
|| getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
displayMetrics);
}
if (size < minTextSize) {
size = minTextSize;
}
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
示例13: applyAttributes
import android.widget.TextView; //導入方法依賴的package包/類
public static void applyAttributes(TextView textView, @Nullable AttributeSet attrs, @StyleableRes int[] styleableIds, @StyleableRes int fontStyableId) {
Context context = textView.getContext();
Typeface typeface = Font.MEDIUM.getTypeface(context);
if (attrs != null) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, styleableIds);
int fontId = typedArray.getInt(fontStyableId, Font.MEDIUM.getId());
typeface = Font.fromId(fontId).getTypeface(context);
typedArray.recycle();
}
textView.setTypeface(typeface);
}
示例14: autofit
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Re-sizes the textSize of the TextView so that the text fits within the bounds of the View.
*/
private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
int maxLines, float precision) {
if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
// Don't auto-size since there's no limit on lines.
return;
}
int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (targetWidth <= 0) {
return;
}
CharSequence text = view.getText();
TransformationMethod method = view.getTransformationMethod();
if (method != null) {
text = method.getTransformation(text, view);
}
Context context = view.getContext();
Resources r = Resources.getSystem();
DisplayMetrics displayMetrics;
float size = maxTextSize;
float high = size;
float low = 0;
if (context != null) {
r = context.getResources();
}
displayMetrics = r.getDisplayMetrics();
paint.set(view.getPaint());
paint.setTextSize(size);
if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
|| getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
displayMetrics);
}
if (size < minTextSize) {
size = minTextSize;
}
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
示例15: HtmlAssetsImageGetter
import android.widget.TextView; //導入方法依賴的package包/類
public HtmlAssetsImageGetter(TextView textView) {
this.context = textView.getContext();
}