我有两个浮动动作按钮。我想以编程方式禁用它们,它只能用于一个按钮。但是另一个总是在UI中启用。当我在日志中查看他的状态时,它说禁用但它正在工作。
这是一段微不足道的代码,但我不明白。
将FloatButtonAction设置为已禁用
fab_nfc.isEnabled = false
fab_sync.isEnabled = false
fab_sync确实被禁用,但另一个没有(在UI中)
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
}