Last active
September 12, 2015 23:58
-
-
Save aegis1980/b138dcb2fd1b2e98aa30 to your computer and use it in GitHub Desktop.
Custom view subclass of Android TextView widget that allows you to use HTML string resources (for better localisation). Development of Millthorn's answer with CDATA tag in this stackoverflow question: http://stackoverflow.com/questions/1529068/is-it-possible-to-have-multiple-styles-inside-a-textview His(Her?) solution required you to programmati…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fitc.views; | |
import android.annotation.TargetApi; | |
import android.content.Context; | |
import android.text.Html; | |
import android.util.AttributeSet; | |
import android.widget.TextView; | |
/** | |
* Created by Jon on 3/01/2015. | |
*/ | |
public class HtmlTextView extends TextView { | |
public HtmlTextView(Context context) { | |
super(context); | |
} | |
public HtmlTextView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public HtmlTextView(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@TargetApi(21) | |
public HtmlTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | |
super(context, attrs, defStyleAttr, defStyleRes); | |
} | |
@Override | |
public void setText(CharSequence s,BufferType b){ | |
super.setText(Html.fromHtml(s.toString()),b); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" > | |
<com.fitc.views.HtmlTextView | |
android:id="@+id/html_TV" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/example_html" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<string name="example_html"> | |
<![CDATA[ | |
<b>Author:</b> Mr Donuthead<br/> | |
<b>Contact:</b> [email protected]<br/> | |
<i>Donuts for life </i> | |
]]> | |
</string> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment