我有一个简单的ListView象下面这样: -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/asimplelistView1"
/>
我通过阵列结合本的ListView ArrayAdapter使用:
ArrayAdapter<string> arrayAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleExpandableListItem1,mItems);
我的应用程序辅助文本颜色为白色(#FFFFFF)和主题是安卓Theme.Material.Light ..
我的问题是:我需要更改项目文本的颜色以灰色,因为项目的文字颜色不是白色背景上可见。
在Java中,我们可以做象下面这样:
// Create a List from String Array elements
List<String> fruits_list = new ArrayList<String>(Arrays.asList(fruits));
// Create an ArrayAdapter from List
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, fruits_list){
@Override
public View getView(int position, View convertView, ViewGroup parent){
// Get the Item from ListView
View view = super.getView(position, convertView, parent);
// Initialize a TextView for ListView each Item
TextView tv = (TextView) view.findViewById(android.R.id.text1);
// Set the text color of TextView (ListView Item)
tv.setTextColor(Color.RED);
// Generate ListView Item using TextView
return view;
}
};
我有同样的情况,并能修复它设置在styles.xml文件中的新“项目”条目:
<项目名称= “机器人:textColorPrimary”> @颜色/ colorAccent </项目>
颜色值可以是任何进入基准您colors.xml或十六进制值