Android 如何随机更改文本化身的颜色

Android 如何随机更改文本化身的颜色,android,Android,我想添加随机颜色的文字头像,而不是一个单一的蓝色 我的名单代码是 list = new ArrayList<>(); for(int i =0;i<data.length();i++){ ModelFriendList temp = new ModelFriendList(); temp.setName(data.getJSONObject(

我想添加随机颜色的文字头像,而不是一个单一的蓝色

我的名单代码是

list = new ArrayList<>();
                    for(int i =0;i<data.length();i++){
                        ModelFriendList temp = new ModelFriendList();
                        temp.setName(data.getJSONObject(i).getString("name"));
                        temp.setUsername(data.getJSONObject(i).getString("phone"));
                        temp.setID(data.getJSONObject(i).getInt("UID"));
                        list.add(temp);
                    }
list=newarraylist();

对于(int i=0;i在您的模型中添加随机颜色的getter setter方法,并从您的模型中添加以下代码和项目集背景色

for(int i =0;i<data.length();i++){
               Random rnd = new Random(); 
               int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); 
               ModelFriendList temp = new ModelFriendList();
               temp.setName(data.getJSONObject(i).getString("name"));
               temp.setUsername(data.getJSONObject(i).getString("phone"));
               temp.setID(data.getJSONObject(i).getInt("UID"));
               temp.setRandomColor(color);
               list.add(temp);
}

for(int i=0;i在模型中添加RandomColor的getter setter方法,并从模型中添加以下代码和项目集背景色

for(int i =0;i<data.length();i++){
               Random rnd = new Random(); 
               int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); 
               ModelFriendList temp = new ModelFriendList();
               temp.setName(data.getJSONObject(i).getString("name"));
               temp.setUsername(data.getJSONObject(i).getString("phone"));
               temp.setID(data.getJSONObject(i).getInt("UID"));
               temp.setRandomColor(color);
               list.add(temp);
}

for(int i=0;i您可以使用random类获得随机颜色

    Random random = new Random(); 
    int color = Color.argb(255, random .nextInt(256), random .nextInt(256), random .nextInt(256));   

之后,您可以在模型中设置这些颜色,并在您想要在视图(即头像)上设置时获得它。

您可以使用random类获得随机颜色

    Random random = new Random(); 
    int color = Color.argb(255, random .nextInt(256), random .nextInt(256), random .nextInt(256));   
之后,您可以在您的模型内设置这些颜色,并在您想要在视图(即化身)上设置时获取这些颜色