如何以编程方式更改GridView单元格的参数?

时间:2016-02-09 18:46:37

标签: android gridview

我有主屏幕(activity_main.xml)。它有一个GridView和2个按钮(红色和绿色)。作为GridView单元的设计,我使用单独的xml文件(content.xml)。我可以通过更改文件中的参数(content.xml)来调整GridView中单元格的图像大小,文本颜色和其他参数。如何以编程方式更改文件(content.xml)中的文本颜色?当您按下文件中的红色和绿色按钮(activity_main.xml)? I drew a diagram

1 个答案:

答案 0 :(得分:0)

您需要在代码中创建一个引用XML文件中TextView对象的对象。

View cell = findViewById(R.layout.content);
TextView cellText = cell.findViewById( // reference to the TextView in xml file );
cellText.setTextColor(Color.parseColor("#000000"));

您可能需要根据XML文件更改某些值。