2

I have been using AppMsg, which is a third party library for displaying alerts in a non intrusive way (originally conceived by Cyril Motier). The library is working out fine for regular activities, but does anyone know how to use the library for Fragments?

https://github.com/johnkil/Android-AppMsg

As can be see, the main function makeText needs an activity context. How do I pass Fragment to this method?

public static AppMsg makeText(Activity context, int resId, Style style)
{
    return makeText(context, context.getResources().getText(resId), style);
} 

Thanks, Torri.

Kumar V
  • 8,810
  • 9
  • 39
  • 58
Torri Veganas
  • 281
  • 1
  • 3
  • 12

3 Answers3

9

You can use my Crouton library for this.

In order to display a Crouton within a Fragment simply call

Crouton.makeText(Activity, String, Style, (ViewGroup) getView()).show();

or

Crouton.showText(Activity, String, Style, (ViewGroup) getView());
Ben Weiss
  • 17,182
  • 6
  • 67
  • 87
  • it will work in child fragment ? it's not displaying anything Crouton.makeText(getActivity(), "err", Style.INFO,(ViewGroup) getView()).show(); //activity-->viewpager fragment--->childfragment – LOG_TAG Nov 01 '13 at 05:08
2

How do I pass Fragment to this method ?

By downloading its source code and modifying it as you see fit. At the present time, AppMsg only supports displaying a crouton at the activity level.

You can set up a crouton via AppMsg from a fragment by passing in the fragment's activity (obtained via getActivity()) to the makeText() method. However, this will still display the crouton for the activity, not for an individual fragment.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • any solutions to make it available for fragment or child(nested) fragment ? (still display the crouton for the activity, not for an individual fragment) !! – LOG_TAG Nov 01 '13 at 05:10
0

The AppMsg library has since been updated with the ability to have the crouton attached to any custom view you provide. Look for the setParent method.

Within a fragment, as long as you have a reference to the container view, it should be straight forward.

KG -
  • 7,130
  • 12
  • 56
  • 72