一排的android ListView的半透明颜色选择 [英] android listview semitransparent selection color of a row

查看:185
本文介绍了一排的android ListView的半透明颜色选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现一个半透明选择一个行的列表视图,并为pressed的状态也。

I need to implement a semi-transparent selection of a row in a listview, and for 'pressed' state also.

如果我申请纯色,那么一切工作正常。但是,如果我申请半透明的颜色(#44444444),然后我看到默认选择颜色(橙色在我的Andr​​oid 2.3),并在它的上面有我的颜色(它变暗橙一点点)。

If I apply solid color, then everything is working as expected. But if I apply semi-transparent color (#44444444) then I see default selection color (orange on my 2.3 android) and on top of it there is my color (it dims orange a little).

为什么会出现在我的一根橙色的颜色吗? 如何解决这个问题呢?

Why is there orange color under my one? How to fix this problem?

下面是我的code: 在绘制/ listselectorinvisible.xml选择XML

Here is my code: Selector xml in drawable/listselectorinvisible.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>

列表视图行布局/ topscore_row.xml定义

Listview row is defined in 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控件本身:

And finally the listview itself:

<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设置色彩失败后,我也试图通过设置listselectorinvisible在我CustomArrayAdapter convertView.setBackgroundResource(R.drawable.listselectorinvisible); ,但没有运气

After failure of setting color in xml, I also tried to set listselectorinvisible in my CustomArrayAdapter via convertView.setBackgroundResource(R.drawable.listselectorinvisible); but no luck.

$ C $的CustomAdapter的C:

Code of the 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;

    }               

感谢你在前进。

推荐答案

您必须设置安卓listSelector =@可绘制/ listcolor中的ListView

You have to set android:listSelector="@drawable/listcolor" in ListView

您的ListView将

Your ListView will be

<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:listSelector="@drawable/listcolor"
android:layout_height="298dip">
</ListView>

对下面的URL来看看

Have a look on the below URl

<一个href="http://android-$c$cs-examples.blogspot.com/2011/03/customized-listview-items-selection.html">How设置选择颜色为ListView控件

谢谢 迪帕克

这篇关于一排的android ListView的半透明颜色选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆