1

//I am setting different TextView with various content as text what I am doing is to set the typeface for all textview. custom font is also displaying fine.

((TextView) findViewById    (R.id.tutor_ps_tv_home))        .setTypeface(mFace);
((TextView) findViewById    (R.id.tutor_ps_tv_plus))        .setTypeface(mFace);
((TextView) findViewById    (R.id.tutor_ps_tv_settings))    .setTypeface(mFace);
((TextView) findViewById    (R.id.tutor_ps_tv_undo))        .setTypeface(mFace);
((TextView) findViewById    (R.id.tutor_ps_tv_cam))         .setTypeface(mFace);
((TextView) findViewById    (R.id.tutor_ps_tv_share))       .setTypeface(mFace);

//Is it possible to set only one id for all text view to change my typeface like this below.

 android:id="@+id/all_textview"
 android:id="@id/all_textview"
 android:id="@id/all_textview"
 android:id="@id/all_textview"

//and I will set in my activity as

 ((TextView) findViewById   (R.id.all_textview))        .setTypeface(mFace);

// did any one know any better sol for this.

Note: I just want to change the typeface not any otherthing/use with the textview.

Padma Kumar
  • 19,893
  • 17
  • 73
  • 130

4 Answers4

1

Is it possible to set only one id for all text view to change my typeface like this below.

No. findViewById() will still return one TextView -- it just will be a random one out of those you gave the same name to.

There are examples floating around StackOverflow and elsewhere of iterating over the children of your content view, finding those that meet your criteria (e.g., are TextViews) and changing their Typeface.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

it seems this post will help you

Android: Want to set custom fonts for whole application not runtime

the answer to the post describes one method. you can pass all the textviews to a function as vararg and change the typeface there

and at the end there is answer with 11 votes (second post from last). the answer describes to use a custom extended textview that has this typeface set. i personally feel this is the better way.

and here is another post

Is it possible to set a custom font for entire of application?

here the reply post from Tom describes how we can set the same font to all views inside an activity

Community
  • 1
  • 1
sunil
  • 6,444
  • 1
  • 32
  • 44
0

I also think that you should set your typeFace in a style and apply it to your application or your activity, you can also inherit in your style from textView and set all textviews to a defined style by default.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">#00FF00</item>
    <item name="android:typeface">monospace</item>
</style>
</resources>

Regards. :)

Goofyahead
  • 5,874
  • 6
  • 29
  • 33
-1

Define a style in res/values/styles.xml and apply it to your Activity. For more information, see: http://developer.android.com/guide/topics/ui/themes.html

EDIT:

My mistake. If CommonsWare says I'm wrong, then I'm wrong. :-)

Sparky
  • 8,437
  • 1
  • 29
  • 41
  • 3
    Can you change typefaces in a style? I was under the impression that was one of the few things you were stuck using Java for. – CommonsWare Jul 11 '12 at 11:27