<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/ac3" ></item> <item android:state_checked="false" android:drawable="@drawable/ac2" ></item> </selector>
这个是用于选项卡的
true 显示一张图
------------------------------------------------------------------------------------------------
这个是再布局文件中设置默认选中状态 背景就是选择器中设置的图片
android:checked="true" android:background="@drawable/shouye"
----------------------------------------------------------------------------------------
这个是画圆的
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#ff00"/> <size android:width="10dp" android:height="10dp"/> </shape>
----------------------------------------------------------------------------------------------
这个是画长条的
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#ff0"/> <size android:width="12dp" android:height="6dp"/> </shape>
----------------------------------------------------------
//设置小圆点 private void setYuanDian(int index){ for (int i = 0; i < listImg.size(); i++) { if(index == i){ listImg.get(i).setImageResource(R.drawable.del_bj); }else { listImg.get(i).setImageResource(R.drawable.edit_bj); } } }
//动态添加小圆点指示器 for (int i = 0; i < listBean.size(); i++) { ImageView imageView = new ImageView(MainViewListView.this); if(i == 0){ imageView.setImageResource(R.drawable.del_bj); }else { imageView.setImageResource(R.drawable.edit_bj); } linearLayout.addView(imageView);//将控件添加到站位布局中 listImg.add(imageView);//将控件添加到集合当中 }