无法禁用对MaterialButton的点击

时间:2019-10-28 11:34:02

标签: android material-design

Android Studio 3.6

样式:

 <style name="buttonStyle" parent="@style/Widget.MaterialComponents.Button">
        <item name="android:textColor">@color/default_button_textColor</item>
        <item name="backgroundTint">@color/button_bg_color</item>
        <item name="android:textAppearance">@style/byttonTexAppearanceStyle</item>
    </style>

在我的xml布局中:

<com.google.android.material.button.MaterialButton
            android:id="@+id/buttonStartSearchBluetooth"
            style="@style/buttonStyle"
            android:layout_width="0dp"
            android:layout_height="@dimen/button_height"
            android:layout_margin="@dimen/button_margin"
            android:onClick="onClickButtonStartSearch"
            android:text="@string/start_search"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

在我的Fragment it成功调用方法onClickButtonStartSearch中,如下所示:

class BluetoothPageFragment : Fragment() {
private lateinit var dataBinding: BluetoothPageFragmentBinding
    private lateinit var bluetoothPageViewModel: BluetoothPageViewModel
   override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        dataBinding =
            DataBindingUtil.inflate(inflater, R.layout.bluetooth_page_fragment, container, false)
        val view = dataBinding.getRoot()
        dataBinding.setHandler(this)
        initLogic()
        return view
    }

 fun onClickButtonStartSearch(view: View) {
            bluetoothPageViewModel.doClickButtonStartSearch()
        }
    }

好。现在,我希望“运行中”禁用单击按钮。所以我试试这个:

dataBinding.buttonStartSearchBluetooth.isClickable = false
            dataBinding.buttonStartSearchBluetooth.isEnabled = false
            dataBinding.buttonStartSearchBluetooth.setFocusableInTouchMode(false)

但是没有帮助。 为什么?

0 个答案:

没有答案