0
내가 가진이 StateListDrawable는 :StateListDrawable 행동 이상한
GradientDrawable gd = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] {
firstColor, secondColor });
StateListDrawable sld = new StateListDrawable();
sld.addState(new int[] { android.R.attr.state_pressed },
new ColorDrawable(onClickColor));
sld.addState(StateSet.WILD_CARD, gd);
이 내 레이아웃입니다 :
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<RelativeLayout
android:id="@+id/actionBar"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:baselineAligned="true"
android:descendantFocusability="afterDescendants">
<ImageButton
android:id="@+id/actionButtonBack"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<ImageButton
android:id="@+id/actionButton3"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/actionButton2" />
<ImageButton
android:id="@+id/actionButton2"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toLeftOf="@+id/actionButton1" />
<ProgressBar
android:id="@+id/actionButton1"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:padding="4dip" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="48dip"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toLeftOf="@+id/actionButton3"
android:layout_toRightOf="@+id/actionButtonBack"
android:gravity="center"
android:textSize="14dip"
android:textStyle="bold" />
</RelativeLayout>
</merge>
그리고이 같은 그리기 가능 설정 :
tv.setClickable(false);
tv.setTextColor(textViewColor);
actionBack.setBackgroundDrawable(sld);
action2.setBackgroundDrawable(sld);
action3.setBackgroundDrawable(sld);
tv.setBackgroundDrawable(sld);
pb.setBackgroundDrawable(sld);
을 난에 클릭하면 actionBack 버튼을 누르면 전체 레이아웃이 onClickButton과 같은 색상이됩니다.
마치 내가 regular-xml-defined 단추 드로어 블을 눌렀던 것처럼 행동하고 싶습니다.
내가 뭘 잘못하고 있니?
문제는 고정 너비가 없다는 것입니다. 진행률 표시 줄과 버튼을 숨길 수 있기 때문에 레이아웃이 필요한만큼 오래 있습니다. – razielsarafan
나는 네가 나에게 한 말을 시도했다. 지금 버튼을 클릭하면 TextView bg가 null이됩니다. 그러나 화면 방향을 전환하면 화면 방향이 바뀌게됩니다. – razielsarafan
예, 경계는 런타임에 적용되며 하드 코드되지 않습니다. 시도를 위해 layout_width를 약간의 딥 값으로 설정하고 작동 여부를 확인하십시오. 그런 다음 결과를 말해 주거나 스크린 샷을 제공하면 도움이됩니다. –