0

イメージ ボタンのフォアグラウンドを 1 秒間保持してから再度変更する必要がある Android アプリケーションを作成しています。だから私は以下のコードを書きました(他のプロジェクトの2つのボタンのテキストの色を変更することに取り組んでいました)。問題は、メインスレッド以外でUI要素を変更していることであり、私は「runOnUiThread」メソッドを使用することはできませんが、現在の関数でその方法を見つけることができないので、誰かが私を助けてくれれば幸いです。

public void waitTime(ImageButton imageButton1, ImageButton imageButton2) {
    HandlerThread handlerThread = new HandlerThread("showText");
    handlerThread.start();
    Handler handler = new Handler(handlerThread.getLooper());
    Runnable runnable = () -> {
        imageButton1.setForeground(AppCompatResources.getDrawable(this, R.color.teal_200));
        imageButton2.setForeground(AppCompatResources.getDrawable(this, R.color.teal_200));
    };
    handler.postDelayed(runnable, 1000);
}
4

1 に答える 1