1

I've got the crouton library ( https://github.com/keyboardsurfer/Crouton ) working with the default layout for notifications. I would like to use a custom layout xml file for the notifications so I could set a different typeface to the TextView to match the rest of my application. I have extended a TextView to get the custom typeface working.

Browsing the source for the library, I found a couple of methods that will probably help me:

public static Crouton make(Activity activity, View customView, ViewGroup viewGroup) {
    return new Crouton(activity, customView, viewGroup);
}

public static Crouton make(Activity activity, View customView) {
    return new Crouton(activity, customView);
}

But I'm struggling to find good example on how to use custom layouts for crouton messages and how I would set the text/message style for them (I have defined some custom styles using Style.Builder()).

The custom layout I want to use is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/uk.co.volume.pinkmothballs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <com.myapp.ui.views.TypefacedTextView
        android:id="@+id/crouton_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="14sp"
        android:gravity="center"
        />

</RelativeLayout>

Can someone point me in the right direction?

boz
  • 4,891
  • 5
  • 41
  • 68

1 Answers1

2

You can a custom Style that uses the resourceId of your text appearance via Style.Builder.setTextAppearance(...).

This takes a reference from your styles.xml and uses it within the internal TextView of the Crouton.

Then you can call Crouton.makeText or Crouton.showText with your custom Style.

Ben Weiss
  • 17,182
  • 6
  • 67
  • 87
  • 1
    Thanks for the answer but I don't think I can use `setTextAppearance` because I'm using non android system fonts by declaring a `Typeface` and then setting it on my custom `TextView`. What else could I try? – boz Mar 05 '13 at 12:23
  • 1
    Extending the library is always a possibility. I like clean pull requests. ;-) Further, you can replace the `TextView` member of `Crouton` with your own `TypefacedTextView`. – Ben Weiss Mar 05 '13 at 12:30
  • 1
    Thank you, I will probably have to go and replace a few lines of code inside the `Crouton` library and add my custom font that way. – boz Mar 05 '13 at 14:01