1. Download our Official Android App: Forums for Android!

App Inventor Trying to change the colour of a resource

Discussion in 'Android Development' started by Jim Calvert, Aug 16, 2017.

  1. Jim Calvert

    Jim Calvert Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Aug 15, 2017

    Aug 15, 2017
    2
    0
    5
    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
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,432
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,432
    10,711
    1,988
    Male
    Software developer
    South West of England
  3. Jim Calvert

    Jim Calvert Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Aug 15, 2017

    Aug 15, 2017
    2
    0
    5
    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
     
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,432
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,432
    10,711
    1,988
    Male
    Software developer
    South West of England
    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.
     

Share This Page

Loading...