浮动动作按钮不被禁用 – Kotlin

我有两个浮动操作按钮。 我想要以编程方式禁用它们,而且它只能用于一个按钮。 但另一个始终在UI中启用。 当我在日志中查看他的状态时,它说禁用,但它正在工作。

这是一个微不足道的代码,但我不明白。

将FloatButtonAction设置为禁用

fab_nfc.isEnabled = false fab_sync.isEnabled = false 

fab_sync真的被禁用,但另一个没有(在用户界面中)

 Log.d(TAG, "Fab NFC isEnabled? = ${fab_nfc.isEnabled}") 

日志文件

日志文件说这个按钮真的被禁用。

 Fab NFC isEnabled? = false 

编辑 – 解释代码示例

activity_main.xml中

 <android.support.design.widget.FloatingActionButton android:id="@+id/fab_sync" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|end" android:layout_margin="@dimen/fab_margin" app:srcCompat="@drawable/ic_synchronization_arrows" /> <include layout="@layout/content_main" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab_nfc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" app:srcCompat="@drawable/ic_nfc_near_field_communication" /> 

content_main.xml

 <FrameLayout android:id="@+id/contentMainFrameLayoutId" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/transparentBackground" android:visibility="gone"> <ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" /> </FrameLayout> 

MainActivity.kt

  private fun disableFloatButtonsAndShowProgressBar() { contentMainFrameLayoutId.visibility = View.VISIBLE fab_nfc.isEnabled = false //not working fab_sync.isEnabled = false //working Timber.d("Fab NFC isEnabled? = ${fab_nfc.isEnabled}") //is false }