미리 정의 된 하나의 배열 색상에서 버튼의 색상을 변경하려고합니다. 이렇게 :
String[] colors = {"#2962ff", "#00bfa5", "#ff6d00", "#aa00ff"};
Random random = new Random();
String myRandString = random.nextInt(colors.length);
// My Buttons
inGridLayout00.setBackgroundColor(myRandString);
inGridLayout01.setBackgroundColor(myRandString);
inGridLayout10.setBackgroundColor(myRandString);
inGridLayout11.setBackgroundColor(myRandString);
그러나 나는 이것을 어떻게 고칠 지 모르겠다.
당신은 잘하고 있지만 난수를 배열로 다시 전달하고 그 임의의 인덱스 번호에 대한 색상을 가져와야합니다
int[] colors = {#2962ff, #00bfa5, #ff6d00, #aa00ff};
Random random = new Random();
int myRandString = random.nextInt(colors.length);
// My Buttons
inGridLayout00.setBackgroundColor(Color.parseColor(colors[myRandString]));
inGridLayout01.setBackgroundColor(Color.parseColor(colors[myRandString]));
inGridLayout10.setBackgroundColor(Color.parseColor(colors[myRandString]));
inGridLayout11.setBackgroundColor(Color.parseColor(colors[myRandString]));
당신이해야 할 일은
setBackgroundColor(colors[myRandString]);
임의의 인덱스 번호의 색상을 가져옵니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다