Using custom styling for crouton library

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

now, I would like to use a custom style instead of the default styles. How can i do this?

Style.ALERT is the 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>

      

+3


source to share


1 answer


It says here :

In general, you can change

display duration size settings text display options custom appearance fade in and out Animation display image

Since style is a common entry point for tuning crotons, go and see for yourself what you can do with it.

You can try changing this class with the following code to change the 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 tested it but I think it should work.

Then below in 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 application, call your crouton with Style.CUSTOM.

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

      

+6


source







All Articles