我有带有集合(listview
)的应用程序小部件。源小部件 xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/widget_list_background"
android:orientation="vertical"
android:paddingBottom="3dip"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingTop="3dip" >
<!-- Header -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<!-- App icon -->
<ImageView
android:id="@+id/widget_list_icon"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_marginRight="3dip"
android:src="@drawable/airplane" />
<!-- Mailbox -->
<TextView
android:id="@+id/widget_list_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="2"
android:text="john@foo.com"
android:textColor="@color/widget_text_primary" />
<!-- Unread count -->
<TextView
android:id="@+id/widget_list_unread"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dip"
android:text="12"
android:textColor="@color/widget_text_secondary"
android:textStyle="bold" />
</LinearLayout>
<!-- Overflow menu -->
<ImageView
android:id="@+id/widget_list_overflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/simple_button_holo"
android:paddingLeft="4dip"
android:paddingRight="4dip"
android:src="@drawable/toolbar_overflow" />
<!-- Line -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginBottom="3dip"
android:layout_marginTop="3dip"
android:background="@color/widget_list_line" />
<!-- Listview with messages -->
<ListView
android:id="@+id/widget_email_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Removed -->
<TextView
android:id="@+id/widget_list_removed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/widget_removed_account"
android:textColor="@color/widget_text_primary"
android:textSize="18dip"
android:textStyle="bold"
android:visibility="gone" />
<!-- Empty list -->
<TextView
android:id="@+id/widget_list_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/widget_inbox_empty"
android:textColor="@color/widget_text_primary"
android:textSize="18dip"
android:textStyle="bold"
android:visibility="gone" />
</LinearLayout>
在布局中存在 imageview (widget_list_overflow)。我设置了 imageview 背景: simple_button_holo
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:drawable="@drawable/simple_button_focused_holo" />
<item android:state_pressed="true"
android:drawable="@drawable/simple_button_pressed_holo" />
<item android:drawable="@android:color/transparent" />
</selector>
问题:ImageView
点击时不仅突出显示ImageView
,而且整体突出layout
,其中ImageView
包含。但是为什么不只是点击ImageView
呢?
PS:感谢codeMagic :)
编辑:(UPD1)我创建 RemoteViews 为:
myview = new RemoteViews(packName, R.layout.mywidget);
Intent svcIntent = new Intent(ctx, WidgetListService.class);
svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
myview.setEmptyView(R.id.widget_email_list, R.id.widget_list_empty_view);
myview.setRemoteAdapter(R.id.widget_email_list, svcIntent);
aAppWidgetManager.updateAppWidget(_widgetId, myview);
我不使用任何 PendingIntent,只设置 TextView 文本并隐藏/显示一些视图。单击时的 logcat 也是空的。