Answer the question
In order to leave comments, you need to log in
How to set the text color of a ListView to black?
I'm trying to understand this source https://github.com/nexes/Android-File-Manager
There was a question, how to make the text on the ListView black, and the background of any other color?
As I understand there is no textColor property for ListView?
Can you please tell me where to add something to change the color?
Answer the question
In order to leave comments, you need to log in
You need to create your own adapter based on BaseAdapter. In it, you can create your own layout for the list item and customize it however you want. Here is the lesson startandroid.ru/ru/uroki/vse-uroki-spiskom/113-urok-54-kastomizatsija-spiska-sozdaem-svoj-adapter.html, or there is a slightly easier option here.
I can’t understand what to specify instead of names (from the example)
public class MainActivity extends Activity {
String[] names = { "Иван", "Марья", "Петр", "Антон", "Даша", "Борис",
"Костя", "Игорь", "Анна", "Денис", "Андрей" };
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// находим список
ListView lvMain = (ListView) findViewById(R.id.lvMain);
// создаем адаптер
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, names);
// присваиваем адаптер списку
lvMain.setAdapter(adapter);
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
/*read settings*/
mSettings = getSharedPreferences(PREFS_NAME, 0);
boolean hide = mSettings.getBoolean(PREFS_HIDDEN, false);
boolean thumb = mSettings.getBoolean(PREFS_THUMBNAIL, true);
int space = mSettings.getInt(PREFS_STORAGE, View.VISIBLE);
int color = mSettings.getInt(PREFS_COLOR, 0);
int sort = mSettings.getInt(PREFS_SORT, 3);
mFileMag = new FileManager();
mFileMag.setShowHiddenFiles(hide);
mFileMag.setSortType(sort);
if (savedInstanceState != null)
mHandler = new EventHandler(Main.this, mFileMag, savedInstanceState.getString("location"));
else
mHandler = new EventHandler(Main.this, mFileMag);
mHandler.setTextColor(color);
mHandler.setShowThumbnails(thumb);
mTable = mHandler.new TableRow();
/*sets the ListAdapter for our ListActivity and
*gives our EventHandler class the same adapter
*/
mHandler.setListAdapter(mTable);
setListAdapter(mTable);
/* register context menu for our list view */
registerForContextMenu(getListView());
mStorageLabel = (TextView)findViewById(R.id.storage_label);
mDetailLabel = (TextView)findViewById(R.id.detail_label);
mPathLabel = (TextView)findViewById(R.id.path_label);
mPathLabel.setText("Путь: /sdcard");
updateStorageLabel();
mStorageLabel.setVisibility(space);
mHandler.setUpdateLabels(mPathLabel, mDetailLabel);
/* setup buttons */
int[] img_button_id = {R.id.help_button, R.id.home_button,
R.id.back_button, R.id.info_button, R.id.multiselect_button, R.id.refresh_btn};
int[] button_id = {R.id.hidden_copy, R.id.hidden_attach,
R.id.hidden_delete, R.id.hidden_move};
ImageButton[] bimg = new ImageButton[img_button_id.length];
Button[] bt = new Button[button_id.length];
for(int i = 0; i < img_button_id.length; i++) {
bimg[i] = (ImageButton)findViewById(img_button_id[i]);
bimg[i].setOnClickListener(mHandler);
if(i < 4) {
bt[i] = (Button)findViewById(button_id[i]);
bt[i].setOnClickListener(mHandler);
}
}
Intent intent = getIntent();
if(intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {
bimg[5].setVisibility(View.GONE);
mReturnIntent = true;
} else if (intent.getAction().equals(ACTION_WIDGET)) {
Log.e("MAIN", "Widget action, string = " + intent.getExtras().getString("folder"));
mHandler.updateDirectory(mFileMag.getNextDir(intent.getExtras().getString("folder"), true));
}
// находим список
ListView lvMain = (ListView) findViewById(R.id.android_list);
// создаем адаптер
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, names);
// присваиваем адаптер списку
lvMain.setAdapter(adapter);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question