Using custom layouts for the crouton library

强颜欢笑 提交于 2019-12-23 03:03:32

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/15223169/using-custom-layouts-for-the-crouton-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!