2015-04-20 113 views
-1

我从文件填充ListViewListvVew包含复选框。现在我想更改单个项目的文字的颜色和字体在复选框上点击。相反,我只能突出显示单个项目行(蓝色)。我错过了什么?更改列表视图中选中项目的文本颜色

main.xml中

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#F3E2A9"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="390dp" 
     android:id="@+id/linearLayoutlist" 
     android:orientation="vertical" 
     > 

    <ListView 
     android:id="@android:id/list" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:choiceMode="multipleChoice" 

     android:drawSelectorOnTop="false" 
     android:listSelector="@drawable/listviewcolor" 

     > 
    </ListView> 
    </LinearLayout> 
    </RelativeLayout> 

listviewcolor.xml

<!-- Selected --> 
<item 
    android:state_focused="true" 
    android:state_pressed="false" 
    android:drawable="@color/red" /> 

<!-- Pressed --> 
<item 
    android:state_pressed="true" 
    android:drawable="@color/blue" /> 

    <!-- Default --> 
    <item android:drawable="@color/lightyellow" /> 

color.xml

<color name="blue">#ff3a8dcb</color>  
<color name="red">#FF0000</color> 
<color name="lightyellow">#F3E2A9</color> 

main_activity

List arrlist=new ArrayList(); 
    ArrayAdapter<String> adapter2; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    listView = getListView(); 
    listView.setChoiceMode(listView.CHOICE_MODE_MULTIPLE); 
    listView.setTextFilterEnabled(true); 

    adapter2 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, android.R.id.text1, arrlist); //arrlist is an ArrayList 
                                 //whose value is taken from a file 
    listView.setAdapter(adapter2); 
     listView.setOnTouchListener(touchListener); 
     listView.setOnScrollListener(touchListener.makeScrollListener()); 
    } 
+0

你的代码在哪里? –

回答

2

您可以更改TextColor和编程TextFont尺寸上CheckboxonCheckedChangeListener()

tx.setTextSize(TypedValue.COMPLEX_UNIT_SP,30); 
tx.setTextColor(Color.WHITE); 
+0

我没有使用复选框。看到我的布局。 'android:choiceMode =“multipleChoice”'使项目在'listview'中可选 – Ted

1

请出示您添加复选框,文本视图和适配器改变文字颜色列表项的布局和在Checkbox onCheckedChangeListener()上动态显示字体,如下所示:

final Typeface tvFont = Typeface.createFromAsset(assetManager, "OPTIMA.TTF"); 
    tv.setTypeface(tvFont); 
    tv.setTextColor(Color.BLACK); 
+0

没有添加“复选框”和“textview”。 android:choiceMode =“multipleChoice”上的'listview'制作复选框。 'listview'布局已经给出 – Ted

+0

请显示您的适配器代码 –

+0

添加了代码。 – Ted

相关问题