Android: Set Random colour background on create

后端 未结 6 1606
既然无缘
既然无缘 2020-12-09 11:38

What I want is when I load my app up it to randomly have a certain colored background from a predefined list of strings stored in a values xml file called colours.

6条回答
  •  醉梦人生
    2020-12-09 12:27

    TRY THIS METHOD SIMPLE AND EASY

    private boolean isOne = false, isTwo = false, isThree = false, isFour = false, isFive = false;
    
    if(position==0){
                holder.llDate.setBackgroundColor(mContext.getResources().getColor(R.color.color1));
                holder.view.setBackgroundColor(mContext.getResources().getColor(R.color.color1));
                isTwo = true;
            }else if(isOne){
                holder.llDate.setBackgroundColor(mContext.getResources().getColor(R.color.color1));
                holder.view.setBackgroundColor(mContext.getResources().getColor(R.color.color1));
                isOne = false;
                isTwo = true;
            }else if(isTwo){
                holder.llDate.setBackgroundColor(mContext.getResources().getColor(R.color.color2));
                holder.view.setBackgroundColor(mContext.getResources().getColor(R.color.color2));
                isTwo = false;
                isThree = true;
            }else if(isThree){
                holder.llDate.setBackgroundColor(mContext.getResources().getColor(R.color.color3));
                holder.view.setBackgroundColor(mContext.getResources().getColor(R.color.color3));
                isThree = false;
                isFour = true;
            }else if(isFour){
                holder.llDate.setBackgroundColor(mContext.getResources().getColor(R.color.color4));
                holder.view.setBackgroundColor(mContext.getResources().getColor(R.color.color4));
                isFour = false;
                isFive = true;
            }else if(isFive){
                holder.llDate.setBackgroundColor(mContext.getResources().getColor(R.color.color5));
                holder.view.setBackgroundColor(mContext.getResources().getColor(R.color.color5));
                isFive = false;
                isOne = true;
            }
    

提交回复
热议问题