A sentimental robot

배경색 자동으로 바꾸기 본문

Android Studio

배경색 자동으로 바꾸기

GOD03219 2018. 2. 1. 17:41

package com.example.i310_54.myapplication08;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

String TAG="EUNBI";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

Handler handler;
public void f1(View view) {

handler=new Handler(){

int r,g,b;
Random rnd=new Random();
LinearLayout ll=findViewById(R.id.ll);
@Override
public void handleMessage(Message msg) {

handler.sendEmptyMessageDelayed(0,1000);

r=rnd.nextInt(256);
g=rnd.nextInt(256);
b=rnd.nextInt(256);

ll.setBackgroundColor(Color.argb(0xff,r,g,b));

}
};

handler.sendEmptyMessage(0);
}


public void f2(View view) {

handler.removeMessages(0);

Button button3=findViewById(R.id.button3);
button3.setEnabled(false);

}


}

'Android Studio' 카테고리의 다른 글

GridLayout2  (0) 2018.02.05
GridLayout  (0) 2018.02.05
TableLayout  (0) 2018.02.01
Transmission  (0) 2018.01.31
Activity  (0) 2018.01.31