activity as dialog in android
try with following property
this.setFinishOnTouchOutside(false);
if you haven't already tried it, then this is the way to achieve activity as dialog: in your manifest file, add to your activity the following attribute:
<activity
android:name=".MyActivityName"
android:theme="@android:style/Theme.Dialog" />
Make change in code as per your need.
Thanks
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:orientation="vertical"
android:paddingBottom="20dp" >
<RelativeLayout
android:id="@+id/RlayMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="30dp"
android:layout_marginTop="120dp"
android:background="#FFFFFF"
android:padding="10dp" >
<TextView
android:id="@+id/txtsignin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="SIGN IN"
android:textColor="#000000"
android:textSize="25sp" />
<EditText
android:id="@+id/edtUserName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtsignin"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/txtuser"
android:hint="USERNAME" />
<EditText
android:id="@+id/edtPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/edtUserName"
android:layout_marginTop="10dp"
android:hint="PASSWORD"
android:inputType="textPassword" />
<Button
android:id="@+id/btnSignIn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/edtPassword"
android:layout_marginTop="10dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Sign In" >
</Button>
<Button
android:id="@+id/btnSignUp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btnSignIn"
android:layout_marginTop="10dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Sign Up For Free!" >
</Button>
</RelativeLayout>
</RelativeLayout>
For the issue of avoiding closing the activity when clicking outside window from API 11 as mentioned by Vivek use this.setFinishOnTouchOutside(false);
but for prior APIs use this code:
@Override
public boolean onTouchEvent(MotionEvent event) {
if ( event.getAction() == MotionEvent.ACTION_DOWN && isOutOfBounds(this, event)){
return true;
}
return super.onTouchEvent(event);
}
private boolean isOutOfBounds(Activity context, MotionEvent event) {
final int x = (int) event.getX();
final int y = (int) event.getY();
final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
final View decorView = context.getWindow().getDecorView();
return (x < -slop) || (y < -slop)
|| (x > (decorView.getWidth()+slop))
|| (y > (decorView.getHeight()+slop));
}