I understand how to do this in design view, but I'm not sure how to create a style based on programmatically created elements. I followed a tutorial and here's where I'm at:
I have a grid view which is populated by a string array as in the code below:
...
gridView = (GridView) findViewById(R.id.gridView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strData);
gridView.setAdapter(adapter);
Each element of the string array populates the grid just fine.
How would I set the text color of the items added to the gridView?
By creating a custom layout and supplying it to your
ArrayAdapter
. Currently you are supplying the default layoutandroid.R.layout.simple_list_item_1
. Create a new layout xml like this:And style it however you want.
You can use it like this:
2 solutions: dynamically or with a custom layout.
Dynamically: you can set a text color by using
setTextColor(...)
when you Override thegetView()
method in your ArrayAdapter, something like this:Custom Layout: this is the simplest way, build a custom layout as:
Then, set it to your adapter:
Even if, you wanted this dynamically, I'm not sure but I think it's better to do with a custom layout.
Hope this helps.