Skip to main content
added 8 characters in body
Source Link
stkent
  • 20.2k
  • 14
  • 90
  • 113

This should do the job:

TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); @ColorInt int color = typedValue.data; 

Also make sure to apply the theme to your Activity before calling this code. Either use:

android:theme="@style/Theme.BlueTheme" 

in your manifest or call (before you call setContentView(int)setContentView(int)):

setTheme(R.style.Theme_BlueTheme) in onCreate() 

in onCreate().

I've tested it with your values and it worked perfectly.

This should do the job:

TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); @ColorInt int color = typedValue.data; 

Also make sure to apply the theme to your Activity before calling this code. Either use:

android:theme="@style/Theme.BlueTheme" 

in your manifest or call (before you call setContentView(int)):

setTheme(R.style.Theme_BlueTheme) in onCreate() 

I've tested it with your values and it worked perfectly.

This should do the job:

TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); @ColorInt int color = typedValue.data; 

Also make sure to apply the theme to your Activity before calling this code. Either use:

android:theme="@style/Theme.BlueTheme" 

in your manifest or call (before you call setContentView(int)):

setTheme(R.style.Theme_BlueTheme) 

in onCreate().

I've tested it with your values and it worked perfectly.

added 3 characters in body
Source Link
Marcin Orlowski
  • 75.7k
  • 11
  • 128
  • 152

This should do the job:

TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); @Color@ColorInt int color = typedValue.data; 

Also make sure to apply the theme to your Activity before calling this code. Either use:

android:theme="@style/Theme.BlueTheme" 

in your manifest or call (before you call setContentView(int)):

setTheme(R.style.Theme_BlueTheme) in onCreate() 

I've tested it with your values and it worked perfectly.

This should do the job:

TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); @Color int color = typedValue.data; 

Also make sure to apply the theme to your Activity before calling this code. Either use:

android:theme="@style/Theme.BlueTheme" 

in your manifest or call (before you call setContentView(int)):

setTheme(R.style.Theme_BlueTheme) in onCreate() 

I've tested it with your values and it worked perfectly.

This should do the job:

TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); @ColorInt int color = typedValue.data; 

Also make sure to apply the theme to your Activity before calling this code. Either use:

android:theme="@style/Theme.BlueTheme" 

in your manifest or call (before you call setContentView(int)):

setTheme(R.style.Theme_BlueTheme) in onCreate() 

I've tested it with your values and it worked perfectly.

makes it clear that typedValue returns a color not a colorRes
Source Link
Patrick
  • 35.4k
  • 11
  • 109
  • 127

This should do the job:

TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); @Color int color = typedValue.data; 

Also make sure to apply the theme to your Activity before calling this code. Either use:

android:theme="@style/Theme.BlueTheme" 

in your manifest or call (before you call setContentView(int)):

setTheme(R.style.Theme_BlueTheme) in onCreate() 

I've tested it with your values and it worked perfectly.

This should do the job:

TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); int color = typedValue.data; 

Also make sure to apply the theme to your Activity before calling this code. Either use:

android:theme="@style/Theme.BlueTheme" 

in your manifest or call (before you call setContentView(int)):

setTheme(R.style.Theme_BlueTheme) in onCreate() 

I've tested it with your values and it worked perfectly.

This should do the job:

TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); @Color int color = typedValue.data; 

Also make sure to apply the theme to your Activity before calling this code. Either use:

android:theme="@style/Theme.BlueTheme" 

in your manifest or call (before you call setContentView(int)):

setTheme(R.style.Theme_BlueTheme) in onCreate() 

I've tested it with your values and it worked perfectly.

added 22 characters in body
Source Link
Emanuel Moecklin
  • 28.9k
  • 11
  • 73
  • 89
Loading
added 53 characters in body
Source Link
Emanuel Moecklin
  • 28.9k
  • 11
  • 73
  • 89
Loading
Source Link
Emanuel Moecklin
  • 28.9k
  • 11
  • 73
  • 89
Loading