3

我正在使用 Crouton 库(https://github.com/keyboardsurfer/Crouton)。

现在,我想使用自定义样式而不是默认样式。我能怎么做 ?

Style.ALERT是默认样式。

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

我想使用这种风格:

@风格:

<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>
4

1 回答 1

6

在这里说:

一般可以修改

文本显示持续时间尺寸设置选项以显示自定义视图外观和消失显示动画图像

由于样式是调整面包块的一般入口点,请亲自去看看可以用它做什么。

您可以尝试使用以下代码修改该类以更改背景颜色:

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();

}

我没有测试它,但我认为它应该工作。

然后在该类下面有以下代码:

 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、重力已经根据您的风格正确设置。

最后,在您的应用程序中,使用 Style.CUSTOM 调用您的面包块。

Crouton.showText(this, "test", Style.CUSTOM);
于 2014-12-19T11:54:13.560 回答