Tuesday, September 13, 2011

Create Transparent Activity

Today we are goning to learn "How to create Transparent Activity ?"
we need to create two activities and a transparent style theme to acheive this.

let's start with creating simple app with default activity "first" and change
main.xml to first.xml in res/layout folder.

  
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class FirstActivity extends Activity 
                implements OnClickListener {
   private Button btnLoad;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first);
        
        
        btnLoad=(Button) findViewById(R.id.btnload);
        btnLoad.setOnClickListener(this);
    }
 @Override
 public void onClick(View v) {
  Intent i = new Intent(this,SecondActivity.class);
        startActivity(i);
  
 }
}

first.xml
  


    

    




then same way create second activity with second.xml file like this
  
package com.rdc;

import android.app.Activity;
import android.os.Bundle;

public class SecondActivity extends Activity {
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);        
    }
}

and the second.xml is
  


  
    
    


now create "styles.xml" in res/values folder
  


  


and also create and color.xml file in res/values
  

  #75AADB
  #00000000


at last make entries for activities and style theme in manifest file
  


    

    
        
            
                
                
            
        
        
        
     
        

    


now if you done all the stuff in right way you will get output like this: (after tapping the button to load transparent activity)

cheers!!

I'd love to hear your thoughts! 

1 comment: