어제 나는 내 버튼이 비활성화 및 활성화 한 후에도 시각적 인 피드백을주지 못하는 문제를 해결하려고했습니다. my problem배경색을 변경 한 후 테두리없는 단추에서 피드백을 얻으려면 어떻게해야합니까? selectableItemBackground
그러나이 단추가 어떻게 표시되는지 내 대답에 맞지 않았습니다. 결국 나는 스톡 버튼을 사용하는 대신 drawables로 내 자신의 버튼을 만든다. 하지만 버튼을 바꾸고 싶지 않다는 단점이 있습니다. 그래서 나는 당신의 도움으로 다른 방법을 찾을 수 있기를 바랍니다. 내가 API (14) 그래서를 일하고 있어요
<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" />
: XML에 How to create standard Borderless buttons
내 버튼 :
알 수있는 importaned 것은 내가 방법으로 주식 버튼을 변경 그것이 그녀를 discriped된다는 것이다 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));
}
그러나 selectableItemBackground에서 funktionality을이 버튼을 돌려 줄 수있는 방법이 있어야합니다.
배경색이 흐릿한 것 같습니다. 누구든지 아이디어가 있습니까? pls 알려주세요
나는 결코 그것을하지 않았기 때문에 나는 나의 자신의 주문 단추를 만들기에 대하여 죽었다. 하지만 당신의 코드 예제에 대해 생각해 보았습니다. 고마워, 지금 나는 새로운 것을 배웠고 계속 나아갈 수있다. :) – Spen