Justice47
Justice47

Reputation: 712

How to set background color programmatically from an app color theme

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

Answers (3)

Simin Ghasemi
Simin Ghasemi

Reputation: 91

You can use this:

view.setBackgroundColor(Color.WHITE);

Upvotes: 0

user2288580
user2288580

Reputation: 2258

This will set the backgroud with alpha

view.setBackgroundDrawable(ColorDrawable(Color.parseColor("#c0ffffff")))

Upvotes: 1

the_dani
the_dani

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

Related Questions