简体   繁体   English

setEnabled(false)->(true)/ selectableItemBackground作为可绘制对象后,没有可见的按钮反馈吗?

[英]No visible button feedback after setEnabled(false) -> (true)/ selectableItemBackground as drawable?

With one button i'm disabling three other button's with button.setEnabled(false). 使用一个按钮,我将通过button.setEnabled(false)禁用其他三个按钮。
That works fine. 很好
When this button is pressed again, the tree button's will be enabled with button.setEnabled(true). 再次按下该按钮时,将使用button.setEnabled(true)启用树形按钮。
They are still doing what they shoud and are fine responding to the onClickListener. 他们仍然在做应做的事情,并且对onClickListener的响应很好。
But since the enabling they do not visible respond when they get pressed. 但是由于启用,它们在被按下时不可见响应。

How do i reactivate them right? 我该如何重新激活它们?
(i already searcht in google but didn't find anything). (我已经在谷歌搜索,但没有找到任何东西)。


private void startSleeping()
{
    editorState.putBoolean("SLEEPING", true);
    editorState.commit();

    buttonDrink.setEnabled(false);
    buttonEat.setEnabled(false);
    buttonWash.setEnabled(false);
    buttonDrink.setBackgroundColor(getResources().getColor(R.color.darkgray));
    buttonEat.setBackgroundColor(getResources().getColor(R.color.darkgray));
    buttonWash.setBackgroundColor(getResources().getColor(R.color.darkgray));
    buttonSleep.setBackgroundColor(getResources().getColor(R.color.orange));
    buttonWash.setTextColor(getResources().getColor(R.color.lightgray));
    buttonDrink.setTextColor(getResources().getColor(R.color.lightgray));
    buttonEat.setTextColor(getResources().getColor(R.color.lightgray));
    buttonSleep.setTextColor(getResources().getColor(color.black));
}

private void stopSleeping()
{
    editorState.putBoolean("SLEEPING", false);
    editorState.commit();

    buttonDrink.setEnabled(true);
    buttonEat.setEnabled(true);
    buttonWash.setEnabled(true);
    buttonDrink.setBackgroundColor(getResources().getColor(R.color.transparent));
    buttonEat.setBackgroundColor(getResources().getColor(R.color.transparent));
    buttonWash.setBackgroundColor(getResources().getColor(R.color.transparent));
    buttonSleep.setBackgroundColor(getResources().getColor(R.color.transparent));
    buttonWash.setTextColor(getResources().getColor(R.color.white));
    buttonDrink.setTextColor(getResources().getColor(R.color.white));
    buttonEat.setTextColor(getResources().getColor(R.color.white));
    buttonSleep.setTextColor(getResources().getColor(R.color.white));
}

        <Button
            android:id="@+id/buttonEat"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:attr/selectableItemBackground"
            android:paddingBottom="@dimen/padding_size"
            android:paddingTop="@dimen/padding_size"
            android:text="@string/button_eat"
            android:textColor="@color/white"
            android:textColorHint="@color/white"
            android:textSize="@dimen/text_size" />

在此处输入图片说明

This is because you are setting the background resource as transparent instead of what you applied in the layout as the background drawable to those buttons. 这是因为您将背景资源设置为透明,而不是将背景资源绘制为可绘制到这些按钮的背景。 Re-apply those background drawables and you'll get the touch feedback again. 重新应用这些背景可绘制对象,您将再次获得触摸反馈。 That should solve your problem. 那应该解决您的问题。

On a side note for future implementations you can directly provide the enabled/disabled background resource in the drawable's list-selector itself. 在将来的实现方面,您可以在可绘制对象的列表选择器本身中直接提供启用/禁用的背景资源。 use state_enabled = true/false. 使用state_enabled = true / false。 This eliminates the need of doing all of that in the code. 这样就无需在代码中完成所有这些操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 按钮:setEnabled(false)不起作用? - Button: setEnabled(false) not working? Android在button.setEnabled(false)上崩溃 - Android crash on button.setEnabled(false) setEnabled(false)之后,jTextArea背景不变 - jTextArea background not changing after setEnabled(false) 调用setEnabled(false)按钮后,仍然可以再按一次 - After calling setEnabled(false) button still can be pressed one more time jbutton.setEnabled(false)不禁用按钮输入 - jbutton.setEnabled(false) doesn't disable button input 为什么我不能使用setEnabled(false)禁用工具栏按钮(操作) - Why I cant disable a toolbar button (action) using setEnabled(false) 更改Backgroundcolor后,如何从无边界按钮获得反馈? selectableItemBackground - How do i get the feedback from Borderless buttons back after changing Backgroundcolor? selectableItemBackground 在setEnabled(true)之后,JButton不会立即获得焦点 - JButton does not gain focus immediately after setEnabled(true) SWT:在Linux上使用setEnabled()后单击按钮的问题 - SWT: problems with clicking button after using setEnabled() on Linux 在调用setVisible(false)后调用set Visible(true)时,我的JFrame内容消失了 - After calling setVisible(false) my JFrame contents are gone when calling set Visible(true)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM