之后的setEnabled(假)无可见按键反馈 - > (真)/ selectableItemBackground为绘制? [英] No visible button feedback after setEnabled(false) -> (true)/ selectableItemBackground as drawable?

查看:229
本文介绍了之后的setEnabled(假)无可见按键反馈 - > (真)/ selectableItemBackground为绘制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过一个按钮即时禁止其他三个按钮与button.setEnabled(假)。

这工作正常。

当该按钮再次pssed $ P $,树按钮的将button.setEnabled(真)启用。

他们仍然在做什么,他们和768,16都很好应对onClickListener。

但由于使他们不可见的回应,当他们得到pressed。

With one button i'm disabling three other button's with button.setEnabled(false).
That works fine.
When this button is pressed again, the tree button's will be enabled with button.setEnabled(true).
They are still doing what they shoud and are fine responding to the onClickListener.
But since the enabling they do not visible respond when they get pressed.

我要如何重新激活他们的权利?

(我已经在searcht谷歌,但没有发现任何东西)。

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.

在一个侧面说明了将来的实现可以直接向在绘制的清单选择器本身的启用/禁用背景资源。使用state_enabled =真/假。这消除了拼尽全力的,在code的需要。

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. This eliminates the need of doing all of that in the code.

这篇关于之后的setEnabled(假)无可见按键反馈 - &GT; (真)/ selectableItemBackground为绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆