我在列表视图中有一个图标和文本列表。图标和文本在列表中是灰色的,背景是白色的。当用户单击一个条目时,图标和文本应该变成白色,输入框的背景变成橙色。
我得到的文字变成白色,背景变成橙色时,我有困难的图像从灰色转到白色,当按下和返回,当它不再按。
我有两套是图片或图标。在“资源”文件夹中,一组为灰色,用于非活动(未按下),一组为白色,为活动(按下)。
当应用程序在前面的代码中通过DrawerItemAdapter加载时,它会加载灰色图标。
mThumbsId是一个包含R.drawable图像的数组。
单击时,我尝试将图像更改为白色图标版本。但是,当它不再被选中时,如何恢复到灰色呢?
mDrawerList.setOnItemClickListener(new DrawerItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
// TODO Auto-generated method stub
Object o = mDrawerList.getItemAtPosition(position);
String pen = o.toString();
Toast.makeText(getApplicationContext(), "You have chosen: " + " " + pen, Toast.LENGTH_SHORT).show();
ImageView image = (ImageView)view.findViewById(R.id.menuImage);
image.setBackgroundResource(mThumbIds[position]);
}
}发布于 2014-01-18 05:21:55
您必须以编程方式编写选择器,并将其设置为ImageView背景。
比如:
StateListDrawable states = new StateListDrawable();
states.addState(new int[] {android.R.attr.state_pressed},
getResources().getDrawable(white image id position));
states.addState(new int[] {},
getResources().getDrawable(grey image id position));
image.setBackgroundResource(states);https://stackoverflow.com/questions/21197256
复制相似问题