0
我有4个选项卡实现的ActionBar。每个标签加载一个片段。在每个片段中,我都有一个带有蓝牙标志的imageView,当蓝牙连接时,此标志应该闪烁。我有这样的方法对所有的碎片以这种方式实现:知道选择了哪个选项卡
public void makeBluetoothBlink() {
btIcon.setImageResource(R.drawable.bluetooth_blink);
AnimationDrawable frameAnimation = (AnimationDrawable) btIcon.getDrawable();
frameAnimation.start();
}
现在,在活动中,我有蓝牙状态,当它连接子监听器,它应该检测哪些片段是可见的。其他可能性是检测选择哪个选项卡。展位选择应该完成这项工作。
我的方法是为每个片段定义一个标签,然后检查哪一个是可见的,并调用该方法使蓝牙标志闪烁。但它不能识别片段中的方法。所以这就是为什么我想知道检测哪个选项卡可能更容易,但我不确定,我不知道该怎么做。
public void onConnecting() {
//Call fragment blink method
Fragment current_fragment = getSupportFragmentManager().findFragmentByTag(tab1);
if (current_fragment.isVisible()) {
current_fragment.makeBluetoothBlink();
}
}