Android Question How to extract wallpaper colors using Monet theme engine on Android 12?

Inman

Well-Known Member
Licensed User
Longtime User
As the title says, Android 12's Material You offers the ability to extract colors from a user's wallpaper and use it in your app. All major Google apps (and a few third party apps) have been updated to support this. Can we do this in B4A? Here is the relevant Java/Kotlin code.

 

tuhatinhvn

Active Member
Licensed User
Longtime User
I think you can use inline java to get this color code (not tested because i dont use Android 12):
B4X:
//import androidx.compose.foundation.isSystemInDarkTheme;
//you can check is darkmode is set too!
import androidx.compose.ui.res.colorResource;

public int colorcodetest_mainDark700(){
return colorResource(android.R.color.system_accent1_700);
}
public int colorcodetest_secondary200(){
return colorResource(android.R.color.system_accent2_200);
}
public int colorcodetest_system_accent1_200(){
return colorResource(android.R.color.system_accent1_200);
}
public int colorcodetest_system_accent1_500(){
return colorResource(android.R.color.system_accent1_500);
}

Use:
B4X:
    Dim nt As JavaObject
    nt.InitializeContext
 Log("Color code is: &    nt.RunMethod("colorcodetest_mainDark700",Null) )
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I think you can use inline java to get this color code (not tested because i dont use Android 12):
B4X:
//import androidx.compose.foundation.isSystemInDarkTheme;
//you can check is darkmode is set too!
import androidx.compose.ui.res.colorResource;

public int colorcodetest_mainDark700(){
return colorResource(android.R.color.system_accent1_700);
}
public int colorcodetest_secondary200(){
return colorResource(android.R.color.system_accent2_200);
}
public int colorcodetest_system_accent1_200(){
return colorResource(android.R.color.system_accent1_200);
}
public int colorcodetest_system_accent1_500(){
return colorResource(android.R.color.system_accent1_500);
}

Use:
B4X:
    Dim nt As JavaObject
    nt.InitializeContext
 Log("Color code is: &    nt.RunMethod("colorcodetest_mainDark700",Null) )
Thanks. I tried your code but I am getting this error. I compiled against SDK 33 and set the targetsdkversion to 33 as well.

B4X:
error: cannot find symbol
return colorResource(android.R.color.system_accent1_700);
       ^
  symbol:   method colorResource(int)
  location: class main
 
Upvote 0
Top