如何更改颜色文本 Android Bootstrap 按钮
How to change the color text Android Bootstrap button
我想更改 AndroidBootStrap 按钮中的文本颜色。
我试过 android:textColor="@color/Pink"
,但文本仍然是黑色。
代码和平,包括 xml 中的 bootstrap 按钮:
<com.beardedhen.androidbootstrap.BootstrapButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
bootstrapbutton:bb_size="xsmall"
android:text="Esporte"
android:textColor="@color/Pink"
bootstrapbutton:bb_icon_left="fa-check-circle-o"
bootstrapbutton:bb_text_alignment="left"
bootstrapbutton:bb_text_gravity="left"
/>
有什么想法吗?
您是否尝试在 create() 中执行此操作??
第一次创建底部时,您可以更改属性,然后将 textColor 设置为粉红色:)
Bootstrap for android 是一个自定义库,具有与 Web 的 bootstrap 默认视图相似的外观和感觉。定制的范围较小。但是如果你真的需要自定义它,那么你可以下载 Library 项目的源代码并在 BootstrapType 构造函数中添加你的自定义属性。这是 BootstrapButton 库的源代码。就像 DEFAULT,PRIMARY 你可以添加一个 CUSTOM 属性 在那里你可以添加你的颜色。
private enum BootstrapType {
DEFAULT("default", R.drawable.bbuton_default, R.drawable.bbuton_default_rounded, R.color.black),
PRIMARY("primary", R.drawable.bbuton_primary, R.drawable.bbuton_primary_rounded, R.color.white),
SUCCESS("success", R.drawable.bbuton_success, R.drawable.bbuton_success_rounded, R.color.white),
INFO("info", R.drawable.bbuton_info, R.drawable.bbuton_info_rounded, R.color.white),
WARNING("warning", R.drawable.bbuton_warning, R.drawable.bbuton_warning_rounded, R.color.white),
DANGER("danger", R.drawable.bbuton_danger, R.drawable.bbuton_danger_rounded, R.color.white),
INVERSE("inverse", R.drawable.bbuton_inverse, R.drawable.bbuton_inverse_rounded, R.color.white);
private final String type;
private final int normalBg;
private final int roundedBg;
private final int textColour;
BootstrapType(String type, int normalBg, int roundedBg, int textColour) {
this.type = type;
this.normalBg = normalBg;
this.roundedBg = roundedBg;
this.textColour = textColour;
}
public static BootstrapType getBootstrapTypeFromString(String type) {
for (BootstrapType value : BootstrapType.values()) {
if (value.type.equals(type)) {
return value;
}
}
return DEFAULT;
}
public int getTextColour() {
return textColour;
}
public int getRoundedBg() {
return roundedBg;
}
public int getNormalBg() {
return normalBg;
}
}
可以在 java 文件中以编程方式完成,但您需要先在 XML 布局文件中为您的按钮添加一个 ID:
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/register_button"
... />
然后,在 Java 文件中:
BootstrapButton b = (BootstrapButton) findViewById(R.id.register_button);
b.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
请注意 getColor(int) 方法在 API 23 中已弃用,您可以将其用作
getColor(int, null)
如果您不支持旧的 API 级别。
我想更改 AndroidBootStrap 按钮中的文本颜色。
我试过 android:textColor="@color/Pink"
,但文本仍然是黑色。
代码和平,包括 xml 中的 bootstrap 按钮:
<com.beardedhen.androidbootstrap.BootstrapButton android:layout_width="fill_parent" android:layout_height="wrap_content" bootstrapbutton:bb_size="xsmall" android:text="Esporte" android:textColor="@color/Pink" bootstrapbutton:bb_icon_left="fa-check-circle-o" bootstrapbutton:bb_text_alignment="left" bootstrapbutton:bb_text_gravity="left" />
有什么想法吗?
您是否尝试在 create() 中执行此操作??
第一次创建底部时,您可以更改属性,然后将 textColor 设置为粉红色:)
Bootstrap for android 是一个自定义库,具有与 Web 的 bootstrap 默认视图相似的外观和感觉。定制的范围较小。但是如果你真的需要自定义它,那么你可以下载 Library 项目的源代码并在 BootstrapType 构造函数中添加你的自定义属性。这是 BootstrapButton 库的源代码。就像 DEFAULT,PRIMARY 你可以添加一个 CUSTOM 属性 在那里你可以添加你的颜色。
private enum BootstrapType {
DEFAULT("default", R.drawable.bbuton_default, R.drawable.bbuton_default_rounded, R.color.black),
PRIMARY("primary", R.drawable.bbuton_primary, R.drawable.bbuton_primary_rounded, R.color.white),
SUCCESS("success", R.drawable.bbuton_success, R.drawable.bbuton_success_rounded, R.color.white),
INFO("info", R.drawable.bbuton_info, R.drawable.bbuton_info_rounded, R.color.white),
WARNING("warning", R.drawable.bbuton_warning, R.drawable.bbuton_warning_rounded, R.color.white),
DANGER("danger", R.drawable.bbuton_danger, R.drawable.bbuton_danger_rounded, R.color.white),
INVERSE("inverse", R.drawable.bbuton_inverse, R.drawable.bbuton_inverse_rounded, R.color.white);
private final String type;
private final int normalBg;
private final int roundedBg;
private final int textColour;
BootstrapType(String type, int normalBg, int roundedBg, int textColour) {
this.type = type;
this.normalBg = normalBg;
this.roundedBg = roundedBg;
this.textColour = textColour;
}
public static BootstrapType getBootstrapTypeFromString(String type) {
for (BootstrapType value : BootstrapType.values()) {
if (value.type.equals(type)) {
return value;
}
}
return DEFAULT;
}
public int getTextColour() {
return textColour;
}
public int getRoundedBg() {
return roundedBg;
}
public int getNormalBg() {
return normalBg;
}
}
可以在 java 文件中以编程方式完成,但您需要先在 XML 布局文件中为您的按钮添加一个 ID:
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/register_button"
... />
然后,在 Java 文件中:
BootstrapButton b = (BootstrapButton) findViewById(R.id.register_button);
b.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
请注意 getColor(int) 方法在 API 23 中已弃用,您可以将其用作
getColor(int, null)
如果您不支持旧的 API 级别。