DiamondGerace
DiamondGerace

Reputation: 101

Transparent Child Activity having black background

I'm fighting with this a bunch of hours and i can't figure out what is happening. I have an app with several tabs. This tabs are being managed by the TabGroupActivity. Inside one of this tabs, I have to start a transparent activity. If I started normally (with startActivity), it looks good, but, obviously, the tab bar is not clickable. Is visible because of the transparency but not "reachable". So, to make the tab bar navegable, I have to "startChildActivity", a method defined to surf through activities inside a particular tab. BUT, when I do that, the activity is shown, but instead of being transparent, the background is black. I tried everything but I can't see how I can fix it. Below is the code where I think the problem could be solved, because it's the only difference between starting an activity and a child activity.

Inside the "main" activity I load all the tabs, each tab has an activity related looking like this:

    public class PreShowTabGroupActivity extends TabGroupActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          startChildActivity("PreshowActivity", new Intent(this, PreshowActivity.class));
        }
    }

The activity that should be transparent is one opened by the "PreshowActivity".

The following is the startChildActivity method inside the TabGroupActivity class. It has my tries to do it transparent, with no luck.

    public void startChildActivity(String Id, Intent intent) {
    Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));

    if (window != null) {

        //window.set
        mIdList.add(Id);
        navController.notifyActivityChange();           
        setContentView(window.getDecorView());
        window.getAttributes().alpha = 0;   
        window.getDecorView().setBackgroundColor(Color.TRANSPARENT);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    }
}

The weird thing is that if I put a color background (like RED or whatever), the background change to that color. But if I configure it transparent, the background is BLACK.

In my Manifest i tried with both Transparent and translucent themes, but with no luck.

If you can help me I will fully appreciate it.

Thanks!

Upvotes: 2

Views: 1989

Answers (1)

EyalBellisha
EyalBellisha

Reputation: 1914

I am sorry for having to use the word "guessing" here, but this is more like an educated "guess". I have had a similar problem where I couldn't figure out why a black background was displayed as transparent. If I had changed that black color to RED for example then it would display the red color. This has to do with a window's property called format. If you change this windo's property like this:

window.getAttributes().format = PixelFormat.TRANSLUCENT; 

This means that a black background would actually be transparent. Now, regarding your question, my "educated guess" is that startChildActivity takes the window's properties of its parent window, while startActivity creates a window with a different set of properties (probably TRANSLUCENT).

Upvotes: 1

Related Questions