Showing posts with label show case view example. Show all posts
Showing posts with label show case view example. Show all posts

Thursday, 23 May 2013

Show Case View Example in Android

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="This is Original View" />

</RelativeLayout>

overlay_view.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/over_lay_image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#50220000" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:text="This is Overlay View" />

</RelativeLayout>

MainActivity.java

package com.rajeshvijayakumar.overlay;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

public class MainActivity extends Activity {

    private ImageView mOverLayImage;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        final Dialog overlayInfo = new Dialog(MainActivity.this);
        overlayInfo.requestWindowFeature(Window.FEATURE_NO_TITLE);
        overlayInfo.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        overlayInfo.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        overlayInfo.setContentView(R.layout.overlay_view);
        overlayInfo.show();
       
        mOverLayImage = (ImageView) overlayInfo.findViewById(R.id.over_lay_image);
        mOverLayImage.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {               
                overlayInfo.cancel();
            }
        });       
    }
}

Output :




Source Code: Download this Example Here