html设置颜色xml,如何使用HTML标记为strings.xml文件中的字符串着色?

我正在创建类似PokéDex的应用程序。我正在使用带有Mike Penz的FastItemAdapter的RecyclerViewer。我的Pokemon类中有多个变量,但我遇到的两个问题是String类型和String弱点。

我的目标是在strings.xml文件中使用HTML标记以添加字体颜色。

在ModelGenerator类中,在其中包含了完整的Pokemon列表,我从strings.xml文件中调用了相应的字符串。

Pokemon(我没有展示吸气剂和吸气剂)

package com.example.pokedex;

import android.os.Parcel;

import android.os.Parcelable;

import androidx.annotation.DrawableRes;

public class Pokemon implements Parcelable {

private final int id;

private final String name;

private final String type;

private final String weakness;

private final int drawableResource;

private final String description;

private final String category;

private final String ability;

private final String abilityDescription;

private final String stats;

private final String height;

private final String weight;

private final String gender;

private Pokemon evolution;

public Pokemon(int id, String name, String type, String weakness, @DrawableRes int drawableResource,

String description, String category, String ability, String abilityDescription,

String stats, String height, String weight, String gender) {

this.id=id;

this.name = name;

this.type = type;

this.weakness = weakness;

this.drawableResource = drawableResource;

this.description = description;

this.category = category;

this.ability = ability;

this.abilityDescription = abilityDescription;

this.stats = stats;

this.height = height;

this.weight = weight;

this.gender = gender;

}

protected Pokemon(Parcel in) {

id = in.readInt();

name = in.readString();

type = in.readString();

weakness = in.readString();

drawableResource = in.readInt();

description = in.readString();

category = in.readString();

ability = in.readString();

abilityDescription = in.readString();

stats = in.readString();

height = in.readString();

weight = in.readString();

gender = in.readString();

evolution = in.readParcelable(Pokemon.class.getClassLoader());

}

@Override

public void writeToParcel(Parcel dest, int flags) {

dest.writeInt(id);

dest.writeString(name);

dest.writeString(type);

dest.writeString(weakness);

dest.writeInt(drawableResource);

dest.writeString(description);

dest.writeString(category);

dest.writeString(ability);

dest.writeString(abilityDescription);

dest.writeString(stats);

dest.writeString(height);

dest.writeString(weight);

dest.writeString(gender);

dest.writeParcelable(evolution, flags);

}

@Override

public int describeContents() {

return 0;

}

public static final Creator CREATOR = new Creator() {

@Override

public Pokemon createFromParcel(Parcel in) {

return new Pokemon(in);

}

@Override

public Pokemon[] newArray(int size) {

return new Pokemon[size];

}

};

strings.xml

Grass\u0020Poison

Fire\u0020Flying\u0020Ice\u0020Psychic

ModelGenerator(为简单起见,我只展示一个口袋妖怪)

package com.example.pokedex;

import android.content.Context;

import java.util.ArrayList;

import java.util.List;

public class ModelGenerator {

public static List < Pokemon > getPokemons(Context context) {

List < Pokemon > pokemons = new ArrayList < > ();

Pokemon bulbasaur = new Pokemon(1, "Bulbasaur", context.getString(R.string.grass_poison), context.getString(R.string.b_i_v_weakness),

R.drawable.bulbizarre, context.getString(R.string.bulbizarre_description), "Seed", "Overgrow",

context.getString(R.string.overgrow_description),

"HP : 2 \nAttack : 3 \nDefense : 2 \nSpecial Attack : 3 \nSpecial Defense : 3 \nSpeed : 3",

"62 cm", "7 kg", "♂ | ♀");

pokemons.add(bulbasaur);

}

}

当我在它们各自的TextView中设置类型和弱点时,它们会显示出来,但不会显示任何颜色。

我想念什么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值