當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。