Using custom style for the crouton library

504 views Asked by At

I am using Crouton lib (https://github.com/keyboardsurfer/Crouton).

now , I would like to use custom style instead of default styles. how can I do ?

Style.ALERT is a default style.

Crouton.showText(this, "test", Style.ALERT);

I want to use this style :

@styles :

<style name="CroutonGreen">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:background">@color/color_pressed_buy_an_item</item>
    <item name="android:gravity">center</item>

</style>
1

There are 1 answers

1
Leandro Temperoni On BEST ANSWER

It says here:

In general you can modify

display duration dimension settings options for the text to display custom Views appearance & disappearance Animation displayed Image

Since Style is the general entry point for tweaking Croutons, go and see for yourself what can be done with it.

You can try modifying that class with the following code to change background color:

static {
ALERT = new Builder()
  .setBackgroundColorValue(holoRedLight)
  .build();
CONFIRM = new Builder()
  .setBackgroundColorValue(holoGreenLight)
  .build();
INFO = new Builder()
  .setBackgroundColorValue(holoBlueLight)
  .build();
CUSTOM = new Builder()
  .setBackgroundColorValue(myColor)
  .build();

}

I haven't test it, but i think it should work.

Then below on that class there is the following code:

 public Builder() {
  configuration = Configuration.DEFAULT;
  paddingInPixels = 10;
  backgroundColorResourceId = android.R.color.holo_blue_light;
  backgroundDrawableResourceId = 0;
  backgroundColorValue = NOT_SET;
  isTileEnabled = false;
  textColorResourceId = android.R.color.white;
  textColorValue = NOT_SET;
  heightInPixels = LayoutParams.WRAP_CONTENT;
  widthInPixels = LayoutParams.MATCH_PARENT;
  gravity = Gravity.CENTER;
  imageDrawable = null;
  imageResId = 0;
  imageScaleType = ImageView.ScaleType.FIT_XY;
  fontName = null;
  fontNameResId = 0;
}

heightInPixels, widthInPixels, gravity are already set correctly according to your style.

Finally, in your app, call your crouton with Style.CUSTOM.

Crouton.showText(this, "test", Style.CUSTOM);