介绍
今天就跟大家聊聊有关这么早Android中实现点击项目改变颜色,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
1。xml布局
& lt;列表视图 android:才能id=癅 + id/left_listview" android:才能layout_width=癿atch_parent" android:才能layout_height=癿atch_parent" android:才能背景=? f4f5f7" android:才能滚动条=皀one"在
2。活动里加载适配器完后添加这两句代码
listViewAdpret.setSelectedPosition(位置); listViewAdpret.notifyDataSetInvalidated ();
3。适配器里面自定义一个变量
private int selectedPosition =, 0;//,选中的位置 public void  setSelectedPosition (int 位置),{ 时间=selectedPosition 才能;位置; }
4。判断是否选择当前项目
if (==selectedPosition 位置),{ itemlayoutb.setBackgroundColor才能(Color.parseColor (“# ffffff")); textc.setTextColor才能(Color.parseColor (“# ff0000")); },{else itemlayoutb.setBackgroundColor才能(Color.TRANSPARENT); textc.setTextColor才能(Color.parseColor (“# 393939“)); }
看完上述内容,你们对这么早Android中实现点击项目改变颜色有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。