Custom Fonts and Custom Textview on Android

The constructor of TextView calls setTypeface(Typeface tf, int style) with the style parameter retrieved from the XML attribute android:textStyle. So, if you want to intercept this call to force your own typeface you can override this method as follow: public void setTypeface(Typeface tf, int style) { Typeface normalTypeface = Typeface.createFromAsset(getContext().getAssets(), “font/your_normal_font.ttf”); Typeface boldTypeface = Typeface.createFromAsset(getContext().getAssets(), … Read more

Android text view color doesn’t change when disabled

I think what’s happening is that since you’re overriding the default textcolor it isn’t inheriting the other textcolor styles. Try creating a ColorStateList for it and setting the textColor attribute to it instead of to a color. In a color file (eg res/color/example.xml): <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_enabled=”false” android:color=”@color/disabled_color” /> <item android:color=”@color/normal_color”/> </selector> … Read more

Android Linkify both web and @mentions all in the same TextView

Here’s my code to linkify all Twitter links (mentions, hashtags and URLs): TextView tweet = (TextView) findViewById(R.id.tweet); TransformFilter filter = new TransformFilter() { public final String transformUrl(final Matcher match, String url) { return match.group(); } }; Pattern mentionPattern = Pattern.compile(“@([A-Za-z0-9_-]+)”); String mentionScheme = “http://www.twitter.com/”; Linkify.addLinks(tweet, mentionPattern, mentionScheme, null, filter); Pattern hashtagPattern = Pattern.compile(“#([A-Za-z0-9_-]+)”); String hashtagScheme … Read more

Copy text from TextView on Android

I think I have a solution. Just call registerForContextMenu(yourTextView); and your TextView will be registered for receiving context menu events. Then override onCreateContextMenu in your Activity: @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { //user has long pressed your TextView menu.add(0, v.getId(), 0, “text that you want to show in the context menu … Read more