вчера я попытался решить проблему, что мои кнопки не дают никакой видимой обратной связи после отключения и включения их. my problemКак получить обратную связь от кнопок Borderless после изменения Backgroundcolor? selectableItemBackground
Но ответы не соответствовали моему желанию, как это будут кнопки. В конце концов выяснилось, что я сделаю свои собственные кнопки с помощью drawables вместо использования кнопок на складе. Но я решил, что я не хочу менять свои кнопки. Так что надеюсь, что с вашей помощью я найду другой способ.
importaned вещь, чтобы знать, что я изменил кнопки запаса в пути он discriped ее: How to create standard Borderless buttons
мои кнопки в 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" />
я работаю с API 14 так API 11 isue не проблема.
У меня есть два способа отключить и включить мои кнопки. После их включения они все еще функционируют, но не дают обратной связи.
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));
}
Но должен быть способ, чтобы дать эти кнопки назад funktionality от selectableItemBackground.
Проблема, кажется, изменение цвета фона. Есть ли у кого-нибудь идеи? pls дайте мне знать
Я был мертв против создания собственных пользовательских кнопок, потому что я никогда не делал этого bevor. Но thx к вашим примерам кода я только что скопировал их, чтобы попытаться, если это будет работать так просто и год. Спасибо, теперь я узнал что-то новое и могу двигаться дальше :) – Spen