-2

アプリで、多色のストロボ ライトを再生したいのですが、どうすればよいですか?

4

2 に答える 2

0

異なる色などが必要な場合はView、XML で を作成して画面幅全体を占めることができます。次に、に基づいて、選択した色にするためにAlarmManager使用できます。setBackground()

Handlerの代わりにを使用する方が有益かもしれませんがAlarmManager、両方を見てニーズに合ったものを確認できます。

于 2012-08-08T19:45:15.580 に答える
-1

画面をさまざまな色で点滅させたい場合は、タイマーを作成し、メイン ビューの背景色を頻繁に変更するだけです。

javax.swing.Timer を使用して、画面を頻繁に変更できます。

Timer colorChanger = new Timer(500 /*milis between each color change*/, new TimeListener(this) );
colorChanger.start();

指定されたアクティビティの背景色を変更する はどこTimeListenerにありますか。ActionListenerTimerListener は次のようになります。

public class TimerListener implements ActionListener {
    public TimerListener(Activity activity) {
        this.backgroundToChange = activity;
    }
    private Activity backgroundToChange = null; // the activity who's background we will change
    private int numFrames = 0; //the number of frames that have passed
    public void actionPerformed(ActionEvent evt) { //happens when the timer will go off
        numFrames++;
        switch ( numFrames % 2 ) { // every other time it will make the background red or green
            case 0: backgroundToChange.getContentView().setBackgroundColor(Color.RED);
            case 1: backgroundToChange.getContentView().setBackgroundColor(Color.GREEN);
        }
    }
}

javax.swing.Timer をインポートする必要があり、ActionListener と ActionEvent は java.awt.event にあります。

ただし、Android を使用している場合は、Timer 以外の Android 用に設計された別のクラスの使用を検討することをお勧めします。タイマーはスイング用に設計されているため、Android で使用するとうまく動作しない場合があります。ただし、クラスのような他のタイマーはタイマーと同様に機能します。

于 2012-08-08T19:52:49.300 に答える