在Android studio中交换ImageView的背景色

在Android studio中交换ImageView的背景色,android,android-studio,mobile,Android,Android Studio,Mobile,我正在尝试交换两个ImageView的背景色。我目前拥有的代码是: ImageView t1 = findViewById(R.id.t1); ImageView f1 = findViewById(R.id.f1); int tempt1 = t1.getSolidColor(); int tempf1 = f1.getSolidColor(); f1.setBackgroundColor(tempt1); t1.setBackgroundCol

我正在尝试交换两个ImageView的背景色。我目前拥有的代码是:

    ImageView t1 = findViewById(R.id.t1);
    ImageView f1 = findViewById(R.id.f1);
    int tempt1 = t1.getSolidColor();
    int tempf1 = f1.getSolidColor();
    f1.setBackgroundColor(tempt1);
    t1.setBackgroundColor(tempf1);

我最初将颜色设置为红色和绿色,但在交换后,它们只显示为白色。

我正在构建一个rubix多维数据集应用程序,交换发生在一个移动多维数据集的函数中。因此,它必须将当前背景色存储在一个临时变量(即tempf1)中,然后将其与另一个磁贴交换(即f1->t1)。所以我只是想找到一种方法来获得当前的背景色。是的,它是这样的!谢谢
ImageView t1 = findViewById(R.id.t1);
ImageView f1 = findViewById(R.id.f1);
Drawable tempf1 = f1.getBackground();
f1.setBackground(t1.getBackground());
t1.setBackground(tempf1);