• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

App Inventor Trying to change the colour of a resource

Jim Calvert

Lurker
Aug 15, 2017
2
0
Hello everyone. This is my First post and I am a real Android newbie.
But I have coded in various other platforms for 50+ years.

My device is a Samsung A5 but that is irrelevant.

I am working with a sample APP on Github called AccelerometerPlay that has 5 small white balls running around the screen with the level of your device. Very simple, I have it compiled and running nicely on my phone.

Here is my frustrating problem: I have searched for hours for a way to programmatically change the colours of the balls from white to other colours.
The balls begin as a PNG resource as below:

class ParticleSystem {
static final int NUM_PARTICLES = 6;
private Particle mBalls[] = new Particle[NUM_PARTICLES];
private Particle mBallX;

ParticleSystem() {
/*
* Initially our particles have no speed or acceleration
*/
for (int i = 0; i < mBalls.length; i++) {
mBalls = new Particle(getContext());
mBalls.setBackgroundResource(R.drawable.ball); <<<<< I want to change the colour about here.
mBalls.setLayerType(LAYER_TYPE_HARDWARE, null);
addView(mBalls, new ViewGroup.LayoutParams(mDstWidth, mDstHeight));
}
}
They are in an array of drawables in a Particle system.
BUT, I cannot find any method anywhere that will change their colours.
And, a couple of times I thought I did find one but could not find the IMPORT to bring it into the APP>

Does anyone have a clue where to look.
Many thanks.
Jim Calvert
 
LV426, thanks for your two links.
Unfortunately they are much help for my situation.
And again, like so many other sample codes, there are NO Import statements .

I am having a heck of a time finding what Import will provide the various methods in question.
Is there a scientific way to figure this out ??
I am beginning to slowly learn that changing the color of anything in Android is tough and inflexible and usually dependent on dynamically frozen XML code.

Thanks
 
Upvote 0
I am having a heck of a time finding what Import will provide the various methods in question.
Is there a scientific way to figure this out ??

You don't have to manually work out what imports are needed by your code. Android Studio will do it automatically as you type in the code. I never ever have to type one single import statement when I'm writing code. And if you press CTRL+ALT+O it will manually trigger an organise import.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones