Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6200701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:25:01+00:00 2026-05-24T04:25:01+00:00

I am a newbie to graphics in Android (although I am pretty well-versed with

  • 0

I am a newbie to graphics in Android (although I am pretty well-versed with Android programming itself). I am trying to display a “lightbulb” in my app. Based on some values, I would like to change the “brightness” of the lightbulb.

I used a PNG image for this.

<View
    android:id="@+id/view2"
    android:layout_width="59dp"
    android:layout_height="65dp"
    android:background="@drawable/lightbulb" />

And, the code is this:

final View normalView = findViewById(R.id.view2);

//Where I need to set the alpha
int alphaValue = /*Some calculation*/
normalView.getBackground().setAlpha(alphaValue);
normalView.invalidate();

The png file is a transparent graphic with only the outline of the bulb in black. Now, what happens is when I set the alpha to a lower value (closer to 0), the entire graphic becomes transparent. I want only the content of the bulb to become transparent. I wish the outline of the bulb to stay visible.

I did try creating my custom View as follows, but now I don’t see the graphic at all.

class LightbulbView extends View {

    private BitmapDrawable mLightbulbDrawable;
    private Paint mPaint;

    /*All constructors which call through to super*/ 

    private void initialize(){
        mLightbulbDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.lightbulb));
        mPaint = new Paint();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mLightbulbDrawable.draw(canvas);
    }

    /*Without this, I get an NPE when I do a getBackground on this view*/
    @Override
    public Drawable getBackground() {
        return mLightbulbDrawable;
        //return super.getBackground();
    }
}

And, of course, using an ImageView does no good either. The result is exactly the same.

<ImageView
    android:layout_width="wrap_content"
    android:id="@+id/imageView1"
    android:layout_height="wrap_content"
    android:src="@drawable/lightbulb"
></ImageView>

And here’s the code

final ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setAlpha(alphaValue);

So, what is the best way to do this in Android?


SOLUTION

This is how I did it. Please see the accepted answer (by @Petrus) for more details:

<FrameLayout
        android:id="@+id/frameLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    >
        <ImageView
            android:layout_height="wrap_content"
            android:src="@drawable/lightbulb_content"
            android:layout_width="wrap_content"
            android:id="@+id/bulbContent"
        ></ImageView>
        <ImageView
            android:layout_height="wrap_content"
            android:src="@drawable/lightbulb"
            android:layout_width="wrap_content"
            android:id="@+id/bulb"
        ></ImageView>

    </FrameLayout>

And in code:

final ImageView bulbContent = (ImageView) findViewById(R.id.bulbContent);
//Where I need to set the alpha
int alphaValue = /*Some calculation*/
normalView.getBackground().setAlpha(alphaValue);
bulbContent.setAlpha(alphaValue);

Here, lightbulb.png is an image with just the outline of the bulb; lightbulb_content.png is an image with the “contents” of the bulb.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:25:02+00:00Added an answer on May 24, 2026 at 4:25 am

    I would use two images, one with the lightbulb outline and one with the content you want to adjust the alpha on.
    Then add the two images using ImageViews in a FrameLayout. First add the image to be adjusted, then the outline image. Make sure both images have the exact same pixel dimensions.

    This way you can adjust the alpha on the bottom image (lightbulb) and keep the outline (top image) unchanged.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a completely newbie to android programming, having done some java for my computing
I am a newbie to Android app development. For 1 of my project, I
I'm newbie to Game programming. I'm trying to develop a simple shooting game. The
Android newbie question here. I've got an app that I'm experimenting with that the
As many newbies to OpenGL and Graphics Programming, I'm having some problems to set
A bit of a newbie question for iOS, just started learning about Core Graphics
Hi I am developing an ipad Magazine app where I need to display pdf
I'm trying to code my first GUI-based game in Java and I chose the
I'm a newbie to Graphics.I'm drawing a rectangle which will change its color after
PHP newbie here, I can't understand what I'm doing wrong here. I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.