Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.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 安卓与色彩_Android_Colors - Fatal编程技术网

Android 安卓与色彩

Android 安卓与色彩,android,colors,Android,Colors,我在android中更改颜色时遇到问题。 我有一个列表,其中我使用以下方法添加元素: colorsPictures.add(Color.BLUE); colorsPictures.add(Color.YELLOW); colorsPictures.add(Color.BLACK); 在onCreate()中,我实现了如下一些功能: colorsPictures.add(Color.BLUE); colorsPictures.add(Color.YELLOW); colorsPictures.a

我在android中更改颜色时遇到问题。 我有一个列表,其中我使用以下方法添加元素:

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
在onCreate()中,我实现了如下一些功能:

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
pictureOne.setImageResource(colorsPictures.get(0)));
pictureTwo.setImageResource(colorsPictures.get(1));
pictureOne和pictureTwo是:

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
    pictureOne = (ImageView) findViewById(R.id.imageViewPicture1);
    pictureTwo = (ImageView) findViewById(R.id.imageViewPicture2);
当我开始活动时,我想将两个imageview的颜色更改为蓝色和黄色。我想我在添加到列表中时有一个bug。我知道我可以在版面中改变颜色,但我必须这样做,这样做。请帮帮我

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
例如:
我有两个布局视图。它们是白色的。我想在运行“活动”并单击按钮时更改它们的颜色。OnClick listener已实现,但当我尝试更改颜色时,会出现nullpointexception。

如果您的唯一目标是更改背景颜色,为什么不这样做呢

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
pictureone.setBackgroundResource(colorsPicture.get(0));

如果你的唯一目标是改变背景的颜色,为什么不这样做呢

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
pictureone.setBackgroundResource(colorsPicture.get(0));

setImageResource的参数是资源id。您正在其中添加颜色。使用:

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
pictureOne.setBackgroundColor(colorsPictures.get(0)));
或在colors.xml中定义yoyr颜色并使用:

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);

pictureTwo.setImageResource(R.color.YOUR\u color\u ID)

setImageResource的参数是资源id。您正在其中添加颜色。使用:

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
pictureOne.setBackgroundColor(colorsPictures.get(0)));
或在colors.xml中定义yoyr颜色并使用:

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);

pictureTwo.setImageResource(R.color.YOUR\u color\u ID)

您已设置为动态,然后您必须像..这样尝试

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
setTextColor(getContext().getResources().getColor(R.color.info_button_text_color));

希望这能对您有所帮助。

您已经设置为动态,然后您就可以像这样尝试了

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
setTextColor(getContext().getResources().getColor(R.color.info_button_text_color));

希望这能对您有所帮助。

问题在于您使用的是
setImageResource(int resId)
,并且方法参数是可绘制的资源,而不是颜色。如果您查看日志,您可能会看到一条警告或异常,说明找不到资源

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
您可以改为使用此选项:

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
pictureOne.setBackgroundColor(colorsPictures.get(0)));
pictureTwo.setBackgroundColor(colorsPictures.get(1));

问题是您使用的是
setImageResource(intresid)
,并且方法参数是可绘制的资源,而不是颜色。如果您查看日志,您可能会看到一条警告或异常,说明找不到资源

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
您可以改为使用此选项:

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
pictureOne.setBackgroundColor(colorsPictures.get(0)));
pictureTwo.setBackgroundColor(colorsPictures.get(1));

setImageResource用于设置drawable文件夹中可用的任何图像,如下所示

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
imageView.setImageResource(R.drawable.myimage);

您正在使用此方法设置具有直接值的颜色。它将给出未知结果,因为在运行时,颜色值将被视为资源id。

setImageResource用于设置可绘制文件夹中可用的任何图像,如下所示

colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
imageView.setImageResource(R.drawable.myimage);

您正在使用此方法设置具有直接值的颜色。它将给出未知结果,因为在运行时,颜色值将被视为资源id。

如果图像视图的背景中有图像,则“更改颜色”将不显示任何背景。它只显示背景图像。有关更多信息,请参阅图像视图背景中的图像,然后更改颜色将不显示任何背景。它将只显示背景图像。有关详细信息,请参阅
colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);