Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android小部件中的Tint/drim视图_Android_Android Widget_Ontouchlistener - Fatal编程技术网

Android小部件中的Tint/drim视图

Android小部件中的Tint/drim视图,android,android-widget,ontouchlistener,Android,Android Widget,Ontouchlistener,我研究并创建了一些android应用程序小部件。所以我有一个小部件,有6个ImageView,当用户点击其中一个时,小部件将启动应用程序 问题是,用户没有反馈他的触摸成功(我的意思是,视图没有着色,因为没有像其他人那样的onTouchListener) 我看到很多小部件可以在用户触摸时着色,但我不能这样做(在RemoteView中,我无法通过视图直接访问)!如何制作?您可以通过如下所示创建自定义绘图并将其设置为ImageView来实现此目的。当用户触摸ImageView时,会显示不同的颜色 wi

我研究并创建了一些android应用程序小部件。所以我有一个小部件,有6个ImageView,当用户点击其中一个时,小部件将启动应用程序

问题是,用户没有反馈他的触摸成功(我的意思是,视图没有着色,因为没有像其他人那样的onTouchListener)


我看到很多小部件可以在用户触摸时着色,但我不能这样做(在RemoteView中,我无法通过视图直接访问)!如何制作?

您可以通过如下所示创建自定义绘图并将其设置为ImageView来实现此目的。当用户触摸ImageView时,会显示不同的颜色

widget_item_image.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:drawable="@color/black_overlay"
    android:state_pressed="true"/>
 <item android:drawable="@color/maroon" android:state_enabled="true"/>
</selector>

希望这会有所帮助。

在您的布局中,所有6个图像视图都是静态的吗?实际上它不是图像视图。这是一个具有compoundDrawable的文本视图,但它是静态的,并且有帮助!我现在只需要更改API<16的setCompoundDrawable
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="100dp"
  android:background="@color/white">

<ImageView
  android:id="@+id/imageView1"
  android:layout_width="200dp"
  android:layout_height="60dp"
  android:src="@drawable/widget_item_image"
  android:scaleType="fitXY"
  android:layout_margin="10dp"/>
</LinearLayout>
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,0);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget_layout);
remoteViews.setOnClickPendingIntent(R.id.imageView1,pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);