我已经使用setAdapter方法将文本插入到ListView中。我找不到在ListView中更改字体颜色的方法。 Google搜索为我提供了他们使用TextView和ListView的结果。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".viewnotesActivity"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/notes_list"
android:divider="@color/colorPrimary"/>
/>
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,layout,list);
ListView lv = findViewById(R.id.notes_list);
lv.setAdapter(adapter);
lv.setBackgroundColor(getColor(R.color.colorPrimary));
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView tv = (TextView)view;
String note = tv.getText().toString();
String file = data.get(position);
Intent intent = new Intent(viewnotesActivity.this,editnoteActivity.class);
intent.putExtra("note",note);
intent.putExtra("file",file);
startActivity(intent);
}
});