[英]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.