Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Modal pop ups and opacity

I'm following the Window (stand alone) example in trying to create a modal popup (Open animation fun on kitchen sink). The example button do not inherit the transparency but when I try to use an image it does. I've tried setting the opacity to 1.0 just for the button but this doesnt work.


tableview.addEventListener('click',function(e)
{
    Ti.API.info("clicked on table view = "+e.source);
    var t = Titanium.UI.create2DMatrix();
    t = t.scale(0);

    var w = Titanium.UI.createWindow({
        backgroundColor:'#000',
        borderWidth:8,
        borderColor:'#888',
        height:400,
        width:300,
        borderRadius:10,
        opacity:0.9,
        transform:t
    });

    // create first transform to go beyond normal size
    var t1 = Titanium.UI.create2DMatrix();
    t1 = t1.scale(1.1);
    var a = Titanium.UI.createAnimation();
    a.transform = t1;
    a.duration = 200;

    // when this animation completes, scale to normal size
    a.addEventListener('complete', function()
    {
        Titanium.API.info('here in complete')
        var t2 = Titanium.UI.create2DMatrix();
        t2 = t2.scale(1.0);
        w.animate({transform:t2, duration:200});

    });

    // create a button to close window
    var b = Titanium.UI.createButton({
        backgroundImage: '../images/popup/modalClose1_1.png',
        backgroundSelectedImage: '../images/popup/modalClose1_2.png',
        top:5,
        lect: 5,
        height:33,
        width:74,
        font:{fontSize:20,fontWeight:'bold',fontFamily:'Helvetica Neue'}
    });

    w.add(b);
    b.addEventListener('click', function()
    {
        var t3 = Titanium.UI.create2DMatrix();
        t3 = t3.scale(0);
        w.close({transform:t3,duration:300});
    });

    w.open(a);
});


win.add(tableview);

Is there anyway to achieve this?

— asked March 19th 2010 by Phi Chong
  • iphone
  • modal
  • opacity
0 Comments

10 Answers

  • you can set the window background to transparent with opacity 1.0 and then add a view

    var view = Titanium.UI.createView({
    backgroundColor:'#000',
    opacity:0.9
    });
    and then add the button to the window with a big zIndex

    I hope this will help you

    — answered February 13th 2011 by Ahmed Hammami
    permalink
    6 Comments
    • This is an older question but it seems that everyone is recycling the same old somewhat broken code. Often times people are giving the window a background color, say "black" and giving the window an opacity setting. What happens when you do this is that EVERYTHING including the contents of what ever else you add to the window will have opacity to them.

      Ahmed gives the correct order, first give your window a backgroundColor = 'transparent' and leave the opacity at 1. Then add a view to the window and give your view a background color and the set the opacity of the view. After that, just keep adding other views to the parent window to complete the modal effect, such.

      — commented February 7th 2013 by Nick Bork
    • thx, good for me.

      — commented August 30th 2013 by Pierre Lesigne
    • It works for me, thank you very much !

      — commented November 4th 2013 by Yasmine B.
    • +1

      — commented November 13th 2013 by Ammar Asim
    • In Alloy I was able to get the effect I wanted by defining my view as shown below. The key seems to be to have the Views on top of each other, not within one another.

      <Alloy>
        <Window>
          <View height="FILL" width="FILL" opacity="0.6" backgroundColor="black" />
          <View height="300dp" width="250dp" borderColor="black" borderWidth="3dp" backgroundColor="white" opacity="1.0">
            <Label text="Here.." />
          </View>
        </Window>
      </Alloy>
      

      — commented January 29th 2014 by Kerry DH
    • great . works for me too

      — commented November 13th 2014 by Geervani BS
  • I'm not sure I understand what you are trying to do? can you provide a link to a screenshot of what you want?

    — answered March 20th 2010 by Nolan Wright
    permalink
    0 Comments
  • I'm referring to this example in the kitchen sink application

    http://apple.7staging.com/modal.jpg

    When I set a background image for that button it inherits the opacity value of the window.

    How do I add textfields and buttons to that example that are not transparent.

    — answered March 20th 2010 by Phi Chong
    permalink
    0 Comments
  • I'm trying to do the same thing.

    If you go to KitchenSink > Base UI > Window (Standalone) then click on Open (Animation Fun) you'll see that it opens a window with a transparent background, but with a non-transparent button inside.

    Setting the opacity on a window like this:

    var myWindow = Ti.UI.createWindow({
       backgroundColor:'#000', 
       width:320, 
       height:460, 
       opacity:0.60
    });
    

    …makes everything transparent, including all child elements. How are you getting the button in the KitchenSink example to not be transparent?


    The effect I'm after is to have a transparent overlay with a little box inside it, with the rest of the app still visible in the background (just like we do modals all over the web).

    Any ideas?

    — answered August 12th 2010 by Clifton Labrum
    permalink
    0 Comments
  • I'm trying to do the same thing.

    If you go to KitchenSink > Base UI > Window (Standalone) then click on Open (Animation Fun) you'll see that it opens a window with a transparent background, but with a non-transparent button inside.

    Setting the opacity on a window like this:

    var myWindow = Ti.UI.createWindow({
       backgroundColor:'#000', 
       width:320, 
       height:460, 
       opacity:0.60
    });
    

    …makes everything transparent, including all child elements. How are you getting the button in the KitchenSink example to not be transparent?


    The effect I'm after is to have a transparent overlay with a little box inside it, with the rest of the app still visible in the background (just like we do modals all over the web).

    Any ideas?

    — answered August 12th 2010 by Clifton Labrum
    permalink
    0 Comments
  • I'm trying to do the same thing.

    If you go to KitchenSink > Base UI > Window (Standalone) then click on Open (Animation Fun) you'll see that it opens a window with a transparent background, but with a non-transparent button inside.

    Setting the opacity on a window like this:

    var myWindow = Ti.UI.createWindow({
       backgroundColor:'#000', 
       width:320, 
       height:460, 
       opacity:0.60
    });
    

    …makes everything transparent, including all child elements. How are you getting the button in the KitchenSink example to not be transparent?


    The effect I'm after is to have a transparent overlay with a little box inside it, with the rest of the app still visible in the background (just like we do modals all over the web).

    Any help?

    — answered August 12th 2010 by Clifton Labrum
    permalink
    0 Comments
  • I posted an answer to this and it looks like the forum choked on it. Good times.

    I'm trying to do the same thing. I want a transparent overlay to cover my app, then a fully opaque view to appear on top of that–just like we do modals all over the web.

    It turns out in the KitchenSink example (Base UI > Window (Standalone) > Open (Animation Fun)) that the "Close" button is transparent. It's just that the opacity is so subtle:

    opacity:0.92;
    

    If you change the opacity to something like 0.50, you'll see that everything in the window inherits the opacity setting.

    Nolan, our question is, how can we have a transparent window background without making everything inside our window transparent?

    — answered August 12th 2010 by Clifton Labrum
    permalink
    0 Comments
  • I posted an answer to this and it looks like the forum choked on it. Good times.

    I'm trying to do the same thing. I want a transparent overlay to cover my app, then a fully opaque view to appear on top of that–just like we do modals all over the web.

    It turns out in the KitchenSink example (Base UI > Window (Standalone) > Open (Animation Fun)) that the "Close" button is transparent. It's just that the opacity is so subtle:

    opacity:0.92;
    

    If you change the opacity to something like 0.50, you'll see that everything in the window inherits the opacity setting.

    Nolan, our question is, how can we have a transparent window background without making everything inside our window transparent?

    — answered August 12th 2010 by Clifton Labrum
    permalink
    0 Comments
  • Whoa… sorry for all the duplicates. It's not my fault–promise!

    So I found a solution for this. Just use two windows. Make one window your transparent background, then open another window right after that that has your stuff in it. Easy peasy.

    — answered August 12th 2010 by Clifton Labrum
    permalink
    0 Comments
  • I was able to get the following to work so that anything I didn't want to have transparency I added to the win element; the win pops up as a small window and the winBG is the transparency behind it:

    var winBG = Titanium.UI.createWindow({
        backgroundColor:'#000',
        opacity:0.60
    });
    var win = Titanium.UI.createWindow({
        height:300,
        top:10,
        right:10,
        left:10,
        borderColor:'#FFF',
        borderWidth:3,
        backgroundColor:'#FF0000',
        borderRadius:3.0
    });
    winBG.open();
    win.open();
    

    I'm using Titanium Mobile 1.6.1 and Android 1.6.

    — answered March 31st 2011 by Joe iEntry
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.