Calligraphy icon indicating copy to clipboard operation
Calligraphy copied to clipboard

I can use Calligraphy in alert dialogs, but fontPath attribute in xml does not have any effect

Open neywen opened this issue 9 years ago • 7 comments

Hello, I have a general knowledge and some experience in programming, particularly in iOS. I'm a bit new with Android, but I'm going forward.

in a Android Studio project, I have a main activity declared as ` public class ProductsActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener

` Calligraphy is inited in the OnCreate callback, with a ttf font I added to the assets/fonts folder, and I override attachBaseContext, as explained in the documentation.

When I open an alert dialog box, I can see it uses the custom default font, that's ok.

But if I use the fontPath attribute in a xml, for a ListView row for instance, it does not apply:

            <TextView
                android:id="@+id/price"
                android:layout_width="match_parent"
                android:layout_height="22dp"
                android:layout_alignBottom="@+id/imageView"
                android:text="price"
                android:textColor="@color/white"
                android:paddingLeft="10dp"
                fontPath="fonts/euclidFlex_regular.ttf"/>

I had to go the row Adapter code, and apply the typeface programmatically to make it work, waiting for me to understand what's wrong with the fontPath thing.

Typeface typeface = Typeface.createFromAsset(mContext.getAssets(), "fonts/euclidFlex_regular.ttf");
 holder.price.setTypeface(typeface);

Is there anything I could check to help me understand the problem ? thanks, loïc b.

neywen avatar Apr 26 '16 09:04 neywen

How are you inflating the View in the Adapter?

You need to make sure you are getting the LayoutInflater correctly. i.e. LayoutInflater.from(this)

chrisjenx avatar Apr 29 '16 22:04 chrisjenx

The Adapter is created using the activity as a context:

new ProductAdapter((Context)ProductsActivity.this, [...]

In the Adapter, I get the view this way :

LayoutInflater inflater = LayoutInflater.from(mContext);
row = inflater.inflate(mLayoutResourceId, parent, false);

neywen avatar Apr 30 '16 05:04 neywen

This may be one of those times you need to change your font to see if it works with a different one.

On Sat, 30 Apr 2016, 07:28 neywen, [email protected] wrote:

The Adapter is created using the activity as a context:

new ProductAdapter((Context)ProductsActivity.this, [...]

In the Adapter, I get the view this way :

LayoutInflater inflater = LayoutInflater.from(mContext); row = inflater.inflate(mLayoutResourceId, parent, false);

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/282#issuecomment-215939753

chrisjenx avatar Apr 30 '16 06:04 chrisjenx

Thanks for answering, The thing is : I know to font works because I see that the activity toolbar title is using it, and I can change the textview font manually with success. The only two problems I noticed :

  • using fontPath attribute directly in the xml does not have any effect
  • the activity toolbar title is shifted if I use Calligraphy (my activity implements NavigationView)

l.

neywen avatar Apr 30 '16 06:04 neywen

Post an example, and I'll have a look. I'm using recycler views with no problems.

On Sat, 30 Apr 2016, 08:21 neywen, [email protected] wrote:

Thanks for answering, The thing is : I know to font works because I see that the activity toolbar title is using it, and I can change the textview font manually with success. The only two problems I noticed :

  • using fontPath attribute directly in the xml does not have any effect
  • the activity toolbar title is shifted if I use Calligraphy (my activity implements NavigationView)

l.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/282#issuecomment-215941512

chrisjenx avatar Apr 30 '16 06:04 chrisjenx

I have the same problem, but only occurs in Android Lollipop

danieltigse avatar Apr 28 '17 22:04 danieltigse

Hello, I have used calligraphy library to set custom font. It is working fine. But, in Samsung 10.1 inch Tab (OS version 6.0.1) text is overlapping in Alert Dialog as well as TextView when there is multiple line. Seems, no space in between lines. How to resolve this as I am not sure about this issue is based on device resolution or something else?

bhagya24 avatar Jun 20 '17 08:06 bhagya24