当前位置: 首页>>代码示例>>Java>>正文


Java TextView.getContext方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:22,代码来源:CustomTextView.java

示例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);
    }
}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:21,代码来源:CustomTextView.java

示例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;
}
 
开发者ID:nichbar,项目名称:Aequorea,代码行数:24,代码来源:AbstractImageLoader.java

示例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);
}
 
开发者ID:JackChan1999,项目名称:WeChatDemo,代码行数:27,代码来源:EmojiUtil.java

示例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;
}
 
开发者ID:HK-SHAO,项目名称:DarkCalculator,代码行数:14,代码来源:AutofitHelper.java

示例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;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:31,代码来源:AutofitHelper.java

示例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;
}
 
开发者ID:WrapOnly,项目名称:android-autofittextview,代码行数:31,代码来源:AutofitHelper.java

示例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);
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:16,代码来源:TextUtil.java

示例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)));
    }
}
 
开发者ID:googlesamples,项目名称:android-EmojiCompat,代码行数:11,代码来源:MainActivity.java

示例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);
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:9,代码来源:Theme0StyleModifier.java

示例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)));
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:8,代码来源:Theme0StyleModifier.java

示例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);
}
 
开发者ID:WrapOnly,项目名称:android-autofittextview,代码行数:50,代码来源:AutofitHelper.java

示例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);
}
 
开发者ID:KwalaGroup,项目名称:Android-Client,代码行数:17,代码来源:TextViewAttrHelper.java

示例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);
}
 
开发者ID:victorminerva,项目名称:AutoResizeEditText,代码行数:50,代码来源:AutofitHelper.java

示例15: HtmlAssetsImageGetter

import android.widget.TextView; //导入方法依赖的package包/类
public HtmlAssetsImageGetter(TextView textView) {
    this.context = textView.getContext();
}
 
开发者ID:SysdataSpA,项目名称:SDHtmlTextView,代码行数:4,代码来源:HtmlAssetsImageGetter.java


注:本文中的android.widget.TextView.getContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。