yesterday i tried to solve the problem that my buttons don't give any visible feedback after disabling and enabling them. my problem
But the answers didn't fit in my wish how this buttons shoud be. In the end it came up that i shoud make my own buttons with drawables instead of using the stock buttons. But i disided that i don't want to change my buttons. So i hope i will finde a other way with your help.
The importaned thing to know is that i changed the stock buttons in the way it is discriped her:How to create standard Borderless buttons
my buttons in xml:
<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" />
I'm working with API 14 so the API 11 isue isn't the problem.
I have two methods witch are disabling and enabling my buttons. After enabling them, they still funktion but give no touch feedback.
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);
// **Her is the problem**
// **if tried diffrent things**
// **First try: (brings back the old color but not the feedback)**
// buttonDrink.setBackgroundColor(android.R.attr.selectableItemBackground);
// **Second try: (App crashes. Why? i don't know. The discription of selectableItemBackground says it is a drawable...)**
//buttonDrink.setBackgroundDrawable(getResources().getDrawable(android.R.attr.selectableItemBackground));
// **Third try: (eclips isn't accepting this because the attribut is a int and not a drawable)**
//buttonDrink.setBackgroundDrawable(android.R.attr.selectableItemBackground);
//**Fourth try: (brings back a feedback but changes the lock, feedback color...)**
TypedArray a = getBaseContext().obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackground});
Drawable backdraw = a.getDrawable(0);
buttonDrink.setBackgroundDrawable(backdraw);
buttonEat.setBackgroundColor(android.R.attr.selectableItemBackground);
buttonWash.setBackgroundColor(android.R.attr.selectableItemBackground);
buttonSleep.setBackgroundColor(android.R.attr.selectableItemBackground);
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));
}
But there must be a way to give these buttons back funktionality from selectableItemBackground.
The problem seems to be the chaning of the background color. Do anyone have any idea? pls let me know