本文整理汇总了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();
}