Reputation: 712
I'm trying to set background color programmatically for a element, which should be same as
<TableRow android:background="@color/colorPrimaryDark">
in xml file. For now on I'm stuck with
row.setBackgroundColor(Color.parseColor("#00ffff"));
, but I dont know how to pass "@color/colorPrimaryDark" here correctly and can't find any relative information in Android documentation.
Upvotes: 0
Views: 3537
Reputation: 2258
This will set the backgroud with alpha
view.setBackgroundDrawable(ColorDrawable(Color.parseColor("#c0ffffff")))
Upvotes: 1
Reputation: 2524
Setting background colors programmatically is easy:
row.setBackgroundResource(R.color.colorPrimaryDark);
For more information: https://developer.android.com/reference/android/view/View#setBackgroundResource(int)
Upvotes: 2