Set background color of TableRow

萝らか妹 提交于 2020-01-02 05:54:22

问题


I try to set the background color of a TableRow. Currently I have this in my XML file:

android:background="@color/buttonBackground" 

and i work great. But when it run

row.setBackgroundColor(R.color.red);

the row disappears. Can someone explain why that is?


回答1:


I believe you need to do:

Resources resource = context.getResources();
row.setBackgroundColor(resource.getColor(R.color.red)



回答2:


You must be missing the alpha value in your color definition. Verify it has 4 bytes, like #FFFFFFFF.




回答3:


You can also try :

row.setBackgroundColor(Color.RED);

This works for me in Android Studio 2.2.3.




回答4:


Just write: android:background="@android:color/buttonBackground"



来源:https://stackoverflow.com/questions/6077391/set-background-color-of-tablerow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!