我需要实现列表视图中一行的半透明选中状态,以及对于“按下”状态也是如此。
如果我使用纯色,那么一切都按预期工作。但是如果我应用半透明的颜色(#44444444),那么我会看到默认的选择颜色(在我的2.3安卓上是橙色),在其上面有我的颜色(它将橙色变暗了一些)。
为什么我的颜色下面还有橙色? 如何解决这个问题?
以下是我的代码: 在drawable/listselectorinvisible.xml中的选择器xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:state_selected="false"
android:drawable="@color/transparent" />
<item android:state_pressed="true"
android:drawable="@color/semitransparent" />
<item android:state_selected="true" android:state_pressed="false"
android:drawable="@color/semitransparent" />
</selector>
Listview的行在layout/topscore_row.xml中定义。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@drawable/listselectorinvisible">
<TextView android:layout_height="wrap_content" android:id="@+id/scrowNum" android:textColor="@color/fontButColor" android:text="#" android:textSize="24sp" android:layout_width="32dip" android:gravity="right|top" android:layout_gravity="top"></TextView>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/scrowNamLay" android:layout_width="142dip" android:orientation="vertical">
<TextView android:layout_height="wrap_content" android:paddingTop="2dip" android:layout_width="fill_parent" android:id="@+id/scrowPlayer" android:textColor="@color/fontButColor" android:text="@string/tblPlayer" android:textSize="24sp" android:paddingLeft="2dip"></TextView>
<TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/scrowOpPlayer" android:textColor="@color/fontButColor" android:text="@string/tblPlayer" android:textSize="14sp" android:paddingLeft="2dip"></TextView>
</LinearLayout>
<ImageView android:id="@+id/scrowImg" android:layout_height="wrap_content" android:src="@drawable/small_im_bt" android:padding="2dip" android:layout_marginTop="2dip" android:layout_width="26dip"></ImageView>
<TextView android:layout_height="wrap_content" android:layout_width="48dip" android:id="@+id/scrowScore" android:layout_marginRight="5dip" android:gravity="right" android:textColor="@color/fontButColor" android:text="@string/tblScore" android:textSize="26sp"></TextView>
<TextView android:layout_height="wrap_content" android:id="@+id/scrowTime" android:textColor="@color/fontButColor" android:text="@string/tblTime" android:gravity="center_horizontal" android:textSize="26sp" android:layout_width="58dip"></TextView>
</LinearLayout>
最后是列表视图本身:
<ListView android:layout_width="match_parent" android:id="@+id/scoreList" android:paddingLeft="5dip" android:paddingRight="5dip"
android:cacheColorHint="#00000000"
android:choiceMode="none"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:longClickable="false" android:layout_height="298dip">
</ListView>
在尝试在xml中设置颜色失败后,我还尝试通过convertView.setBackgroundResource(R.drawable.listselectorinvisible);在我的CustomArrayAdapter中设置listselectorinvisible,但没有成功。
CustomAdapter的代码:
/* (non-Javadoc)
* @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
*/
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.topscore_row, null);
}
Score score = objects.get(position);
int color = getColor(position, score);
if (score != null)
{
ImageView iv = (ImageView) v.findViewById(R.id.scrowImg);
if (iv != null)
{
iv.setImageResource(imgs[score.gameType]);
}
TextView tv = (TextView) v.findViewById(R.id.scrowNum);
tv.setText(Integer.toString(position+1) + ".");
tv.setTypeface(app.mainFont);
tv.setTextColor(color);
.... ....
}
v.setBackgroundResource(R.drawable.listselectorinvisible);
return v;
}
Thank you in advance.