2011-04-12 6 views
0

홈 화면 위젯을 만들고 있습니다. 위젯은 눌리고 초점을 맞출 때 "정상적인"배경색을 가져야합니다. 다른 경우에는 투명합니다. 안드로이드 위젯 초점을 맞춘 배경색

그러므로 나는 선택

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_focused="true" android:state_pressed="true" 
    android:drawable="@drawable/widget_back_pressed" /> 
<item android:state_focused="false" android:state_pressed="true" 
    android:drawable="@drawable/widget_back_pressed" /> 
<item android:state_focused="true" android:drawable="@drawable/widget_back_selected" /> 
<item android:state_focused="false" android:state_pressed="false" 
    android:drawable="@drawable/transparent" /> 

대부분 모든 포커스 된 상태를 제외하고 잘 작동을 정의했습니다. 위젯이 홈 화면에 있고 D- 패드 또는 키보드 (에뮬레이터에서)로 초점을 맞춘 경우 선택한 색상이 표시되지 않습니다. 눌려진 색상이 잘 작동합니다.

뭐가 잘못 되었나요? 저도 같은 문제가 있었다

+0

응용 프로그램 위젯에 포커스가 없습니다. AFAIK. – CommonsWare

+0

@CommonsWare GoogleReader의 위젯이 배경색을 변경합니다. – Till

답변

0

까지

감사와 안부. 내 ImageView를 포커스 가능하게 만들고 부모 레이아웃이 아닌지 확인하여 문제를 해결했습니다. 또한

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/widget" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/transparent" > 

    <RelativeLayout 
    android:id="@+id/relativeLayoutWidget1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <ImageView 
     android:id="@+id/logo" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:layout_centerInParent="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 

     android:maxHeight="72dp" 
     android:maxWidth="72dp" 
     android:scaleType="fitXY" 
     android:background="@drawable/btn_widget_background" 
     android:src="@drawable/widget_icon" /> 
    </RelativeLayout> 
</LinearLayout> 

당신이 포커스 항목을 올바르게 onClickPendingIntent을 설정해야합니다, 그렇지 않으면 당신의 위젯은 하드웨어 버튼을 클릭 할 수 없습니다. 따라서이 경우 AppWidgetProvider에서 :

views.setOnClickPendingIntent(R.id.logo, pendingIntent); 
관련 문제