Android StyleSpan - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android StyleSpan class.

This code example shows how to use the following methods:
     * 
     * @param text 
     * @return this text 
     */ 
    public StyledText bold(final CharSequence text) {
        return append(text, new StyleSpan(BOLD));
    } 
 
    /** 
     * Append text in bold 
     * 
     * @param text 
     * @param color 
     * @return this text 
     */ 
    public StyledText background(final CharSequence text, final int color) {
        return append(text, new BackgroundColorSpan(color));
    } 
 
    /** 
7
CodeRank
This code example shows how to use the following methods:
		map.put("font-weight", this);
	} 
 
	@Override 
	public ParcelableSpan getSpan(SpannableStringBuilder mSB, String value) {
		return new StyleSpan(value.equals("normal") || value.equals("400") ? Typeface.NORMAL : Typeface.BOLD);
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:
 
    private TextView mChannelView;
    private TextView mMessageView;
    private TextView mDateView;
 
    private static final StyleSpan STYLE_BOLD = new StyleSpan(Typeface.BOLD);
 
    public CellBroadcastListItem(Context context) {
        super(context);
    } 
 
    public CellBroadcastListItem(Context context, AttributeSet attrs) {
        super(context, attrs);
    } 
 
    CellBroadcastMessage getMessage() { 
        return mCbMessage;
    } 
 
    @Override 
6
CodeRank
This code example shows how to use the following methods:
        @Override 
        public void setText(CharArrayBuffer baseText, CharArrayBuffer highlightedText) {
            append(new String(baseText.data, 0, baseText.sizeCopied));
            append(' ');
            append(new String(highlightedText.data, 0, highlightedText.sizeCopied));
            setSpan(new StyleSpan(Typeface.ITALIC), 0, baseText.sizeCopied, 0);
            setSpan(new StyleSpan(Typeface.ITALIC), baseText.sizeCopied + 1,
                    baseText.sizeCopied + 1 + highlightedText.sizeCopied, 0);
        } 
    } 
 
    @Override 
    public TextWithHighlighting createTextWithHighlighting() { 
        return new TestTextWithHighlighting(); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:
    // For posting UI update Runnables from other threads: 
    private Handler mHandler = new Handler();
 
    private Conversation mConversation;
 
    public static final StyleSpan STYLE_BOLD = new StyleSpan(Typeface.BOLD);
 
    public ConversationListItem(Context context) {
        super(context);
    } 
 
    public ConversationListItem(Context context, AttributeSet attrs) {
        super(context, attrs);
 
        if (sDefaultContactImage == null) {
            sDefaultContactImage = context.getResources().getDrawable(R.drawable.ic_contact_picture);
        } 
    } 
 
    @Override 
6
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:
     * @return CharSequence The non highlighted name string 
     */ 
    public static CharSequence getNonHighlightedName(SearchResult result) {
        String name = result.getFso().getName();
        Spannable span = new SpannableString(name);
        span.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
        return span;
    } 
 
    /** 
     * Method that converts the list of file system object to a search result. 
     * 
     * @param files The files to convert 
     * @param queries The terms of the search 
     * @return List<SearchResult> The files converted 
     */ 
    public static List<SearchResult> convertToResults(List<FileSystemObject> files, Query queries) {
        //Converts the list of files in a list of search results 
        List<SearchResult> results = new ArrayList<SearchResult>(files.size());
        int cc = files.size();
5
CodeRank
This code example shows how to use the following methods:
			 
				int ini = txtTexto.getSelectionStart();
				int fin = txtTexto.getSelectionEnd();
				 
				texto.setSpan(
						new StyleSpan(android.graphics.Typeface.BOLD), 
						ini, fin, 
						Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			} 
		}); 
         
        btnSetText = (Button)findViewById(R.id.BtnSetText);
        btnSetText.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0)
			{ 
				Editable str = Editable.Factory.getInstance().newEditable("Esto es un simulacro.");
				str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 11, 20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
				txtTexto.setText(str);
				 
				//Nueva cadena de texto 
5
CodeRank
This code example shows how to use the following methods:setSpan
            } else { 
                ((Spannable)((CommentView) convertView).userTexView.getText()).setSpan(new ForegroundColorSpan(Color.rgb(255, 200, 0)), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            } 
 
        } 
        ((Spannable)((CommentView) convertView).userTexView.getText()).setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 
        return convertView;
    } 
 
    private void createSpanSections(Spannable str, int[] styled) {
        str.setSpan(new ForegroundColorSpan(Color.BLACK), styled[0], styled[1], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        str.setSpan(new ForegroundColorSpan(Color.GRAY), styled[1], styled[2], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), styled[1], styled[2], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } 
 
    private class CommentView extends LinearLayout {
        public TextView commentTextView;
        public TextView userTexView;
 
5
CodeRank
This code example shows how to use the following methods:
    @SmallTest 
    public void testMarkup() throws Exception { 
        SpannableString s;
 
        s = new SpannableString("Hello bold world");
        s.setSpan(new StyleSpan(Typeface.BOLD), 6, s.length() - 6,
                  Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        assertEquals(Html.toHtml(s), "<p>Hello <b>bold</b> world</p>\n");
 
        s = new SpannableString("Hello italic world");
        s.setSpan(new StyleSpan(Typeface.ITALIC), 6, s.length() - 6,
                  Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        assertEquals(Html.toHtml(s), "<p>Hello <i>italic</i> world</p>\n");
 
        s = new SpannableString("Hello monospace world");
        s.setSpan(new TypefaceSpan("monospace"), 6, s.length() - 6,
                  Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        assertEquals(Html.toHtml(s), "<p>Hello <tt>monospace</tt> world</p>\n");
 
        s = new SpannableString("Hello superscript world");
5
CodeRank

Related Android StyleSpan Questions & Answers:

See Code Examples for Android StyleSpan Methods: