Search in sources :

Example 66 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project MarqueeView by sfsheng0322.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    marqueeView = (MarqueeView) findViewById(R.id.marqueeView);
    marqueeView1 = (MarqueeView) findViewById(R.id.marqueeView1);
    marqueeView2 = (MarqueeView) findViewById(R.id.marqueeView2);
    marqueeView3 = (MarqueeView) findViewById(R.id.marqueeView3);
    marqueeView4 = (MarqueeView) findViewById(R.id.marqueeView4);
    List<CharSequence> list = new ArrayList<>();
    SpannableString ss1 = new SpannableString("1、MarqueeView项目");
    ss1.setSpan(new ForegroundColorSpan(Color.RED), 2, 13, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    list.add(ss1);
    SpannableString ss2 = new SpannableString("2、GitHub:sfsheng0322");
    ss2.setSpan(new ForegroundColorSpan(Color.GREEN), 9, 20, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    list.add(ss2);
    SpannableString ss3 = new SpannableString("3、个人博客:sunfusheng.com");
    ss3.setSpan(new URLSpan("http://sunfusheng.com/"), 7, 21, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    list.add(ss3);
    list.add("4、孙福生微博,请粉哦");
    marqueeView.startWithList(list);
    marqueeView1.startWithText(getString(R.string.marquee_texts));
    marqueeView2.startWithText(getString(R.string.marquee_texts));
    marqueeView3.startWithText(getString(R.string.marquee_texts));
    marqueeView4.startWithText(getString(R.string.marquee_text));
    marqueeView.setOnItemClickListener(new MarqueeView.OnItemClickListener() {

        @Override
        public void onItemClick(int position, TextView textView) {
            Toast.makeText(getApplicationContext(), textView.getText() + "", Toast.LENGTH_SHORT).show();
        }
    });
    marqueeView1.setOnItemClickListener(new MarqueeView.OnItemClickListener() {

        @Override
        public void onItemClick(int position, TextView textView) {
            Toast.makeText(getApplicationContext(), String.valueOf(marqueeView1.getPosition()) + ". " + textView.getText(), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : SpannableString(android.text.SpannableString) MarqueeView(com.sunfusheng.marqueeview.MarqueeView) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) URLSpan(android.text.style.URLSpan)

Example 67 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project android_frameworks_base by crdroidandroid.

the class HtmlToSpannedConverter method endCssStyle.

private static void endCssStyle(Editable text) {
    Strikethrough s = getLast(text, Strikethrough.class);
    if (s != null) {
        setSpanFromMark(text, s, new StrikethroughSpan());
    }
    Background b = getLast(text, Background.class);
    if (b != null) {
        setSpanFromMark(text, b, new BackgroundColorSpan(b.mBackgroundColor));
    }
    Foreground f = getLast(text, Foreground.class);
    if (f != null) {
        setSpanFromMark(text, f, new ForegroundColorSpan(f.mForegroundColor));
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) BackgroundColorSpan(android.text.style.BackgroundColorSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 68 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project smartmodule by carozhu.

the class StringUtil method highlight.

/**
     * hightlight text
     *
     * @param start
     * @param end
     * @param text
     */
public static void highlight(int start, int end, TextView text, int color) {
    SpannableStringBuilder spannable = new SpannableStringBuilder(text.getText().toString());
    ForegroundColorSpan span = new ForegroundColorSpan(color);
    spannable.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    text.setText(spannable);
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 69 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project android_frameworks_base by crdroidandroid.

the class FlashlightTile method handleUpdateState.

@Override
protected void handleUpdateState(BooleanState state, Object arg) {
    state.label = mHost.getContext().getString(R.string.quick_settings_flashlight_label);
    if (!mFlashlightController.isAvailable()) {
        Drawable icon = mHost.getContext().getDrawable(R.drawable.ic_signal_flashlight_disable).mutate();
        final int disabledColor = mHost.getContext().getColor(R.color.qs_tile_tint_unavailable);
        icon.setTint(disabledColor);
        state.icon = new DrawableIcon(icon);
        state.label = new SpannableStringBuilder().append(state.label, new ForegroundColorSpan(disabledColor), SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
        state.contentDescription = mContext.getString(R.string.accessibility_quick_settings_flashlight_unavailable);
        return;
    }
    if (arg instanceof Boolean) {
        boolean value = (Boolean) arg;
        if (value == state.value) {
            return;
        }
        state.value = value;
    } else {
        state.value = mFlashlightController.isEnabled();
    }
    final AnimationIcon icon = state.value ? mEnable : mDisable;
    state.icon = icon;
    state.contentDescription = mContext.getString(R.string.quick_settings_flashlight_label);
    state.minimalAccessibilityClassName = state.expandedAccessibilityClassName = Switch.class.getName();
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Drawable(android.graphics.drawable.Drawable) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 70 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project little-bear-dictionary by daimajia.

the class QueryProcessor method processOneItem.

/**
	 * 对每一个单词条目生成textview
	 * 
	 * @param context
	 * @param cursor
	 * @param dictionaryParseInfomation
	 * @param index
	 * @return
	 */
private TextView processOneItem(Context context, Cursor cursor, DictionaryParseInfomation dictionaryParseInfomation, int index) {
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    TextView textView = new TextView(context);
    for (EchoViews echoView : dictionaryParseInfomation.echoViews) {
        textView.setLayoutParams(layoutParams);
        textView.setPadding(DisplayUtils.dip2px(context, echoView.view_padding_left), DisplayUtils.dip2px(context, echoView.view_padding_top), DisplayUtils.dip2px(context, echoView.view_padding_right), DisplayUtils.dip2px(context, echoView.view_padding_bottom));
        ArrayList<SpannableString> contents = new ArrayList<SpannableString>();
        CharacterStyle colorCharacterStyle = null, sizeCharacterStyle = null;
        for (TextArg textArg : echoView.sprintfArgs) {
            String content = cursor.getString(cursor.getColumnIndex(textArg.argContent)) + "  ";
            SpannableString partString = dealAction(textArg, content);
            colorCharacterStyle = null;
            sizeCharacterStyle = null;
            if (mIsGlobal) {
                colorCharacterStyle = new ForegroundColorSpan(mGlobalColor);
                sizeCharacterStyle = new AbsoluteSizeSpan(mGlobalSize);
            }
            if (mIsIndividual) {
                if (mIsIndividualProperty && textArg.type.equalsIgnoreCase("property")) {
                    colorCharacterStyle = new ForegroundColorSpan(mPropertyColor);
                    sizeCharacterStyle = new AbsoluteSizeSpan(mPropertySize);
                } else if (mIsIndividualEnglish && textArg.type.equalsIgnoreCase("english")) {
                    colorCharacterStyle = new ForegroundColorSpan(mEnglishColor);
                    sizeCharacterStyle = new AbsoluteSizeSpan(mEnglishSize);
                } else if (mIsIndividualChinese && textArg.type.equalsIgnoreCase("chinese")) {
                    colorCharacterStyle = new ForegroundColorSpan(mChineseColor);
                    sizeCharacterStyle = new AbsoluteSizeSpan(mChineseSize);
                } else if (mIsIndividualExample && textArg.type.equalsIgnoreCase("example")) {
                    colorCharacterStyle = new ForegroundColorSpan(mExampleColor);
                    sizeCharacterStyle = new AbsoluteSizeSpan(mExampleSize);
                }
            }
            if (colorCharacterStyle == null || sizeCharacterStyle == null) {
                if (mIsGlobal) {
                    colorCharacterStyle = new ForegroundColorSpan(mGlobalColor);
                    sizeCharacterStyle = new AbsoluteSizeSpan(mGlobalSize);
                } else {
                // theme style
                }
            }
            partString.setSpan(colorCharacterStyle, 0, partString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            partString.setSpan(sizeCharacterStyle, 0, partString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            contents.add(partString);
        }
        CharSequence resultContent = TextUtils.concat(contents.toArray(new SpannableString[0]));
        SpannableString IndexSpannableString = new SpannableString(index + ".");
        if (mIsIndividual && mIsIndividualTermNum) {
            colorCharacterStyle = new ForegroundColorSpan(mTermNumColor);
            sizeCharacterStyle = new AbsoluteSizeSpan(mTermNumSize);
        } else if (mIsGlobal) {
            colorCharacterStyle = new ForegroundColorSpan(mGlobalColor);
            sizeCharacterStyle = new AbsoluteSizeSpan(mGlobalSize);
        } else {
        // Theme style
        }
        IndexSpannableString.setSpan(colorCharacterStyle, 0, IndexSpannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        IndexSpannableString.setSpan(sizeCharacterStyle, 0, IndexSpannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        resultContent = TextUtils.concat(IndexSpannableString, resultContent);
        textView.setText(resultContent);
    }
    return textView;
}
Also used : SpannableString(android.text.SpannableString) LayoutParams(android.view.ViewGroup.LayoutParams) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) SpannableString(android.text.SpannableString) EchoViews(com.zhan_dui.dictionary.datacenter.DictionaryParseInfomation.EchoViews) TextArg(com.zhan_dui.dictionary.datacenter.DictionaryParseInfomation.TextArg) CharacterStyle(android.text.style.CharacterStyle) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan)

Aggregations

ForegroundColorSpan (android.text.style.ForegroundColorSpan)157 SpannableStringBuilder (android.text.SpannableStringBuilder)57 SpannableString (android.text.SpannableString)50 StyleSpan (android.text.style.StyleSpan)25 TextView (android.widget.TextView)25 ImageSpan (android.text.style.ImageSpan)23 Spannable (android.text.Spannable)22 RelativeSizeSpan (android.text.style.RelativeSizeSpan)22 View (android.view.View)22 BackgroundColorSpan (android.text.style.BackgroundColorSpan)19 TypefaceSpan (android.text.style.TypefaceSpan)16 StrikethroughSpan (android.text.style.StrikethroughSpan)14 UnderlineSpan (android.text.style.UnderlineSpan)13 Drawable (android.graphics.drawable.Drawable)12 CharacterStyle (android.text.style.CharacterStyle)11 EditText (android.widget.EditText)11 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)8 LinearLayout (android.widget.LinearLayout)8 URLSpan (android.text.style.URLSpan)7