1
我正在寻找一种方法来关闭对话框中使用的xml内的按钮关闭自定义对话框,或者通过按下对话框中的任意位置关闭它。我拥有的是这个;一个带有图像按钮的布局,可以打开带有内容的自定义对话框。我已setCanceledOnTouchOutside(true);并且工作正常,但我需要填充大部分屏幕的对话框,并且用户可能很难点击可用的小空间。那么,我该如何做到这一点?Android中关闭布局中的自定义对话框
我的Java代码:
import android.app.Activity;
import android.app.Dialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class Rose extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.rose);
ImageButton b = (ImageButton) findViewById(R.id.imageButton1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Dialog d1 = new Dialog(Rose.this);
d1.setContentView(R.layout.tariquet);
d1.setCanceledOnTouchOutside(true);
d1.show();
}
});
}
}
我的XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:isScrollContainer="true"
android:minHeight="1100dp"
android:minWidth="650dp">
<ImageView
android:src="@drawable/rose_tariquet"
android:id="@+id/imageView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"></ImageView>
<Button android:text="X"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:layout_width="55dp"
android:layout_gravity="right"></Button>
</FrameLayout>
我似乎无法得到那个工作,不知道我做错了什么。我使用上面的代码创建了一个名为CustomizeDialog的新Java文件,并替换了ID。 – condensation 2012-01-05 02:45:58
我在编辑它,你可以试试吗? – pengwang 2012-01-05 06:28:49
我在哪里放?如果我把它放在代码的末尾,我会遇到一堆语法错误。 – condensation 2012-01-05 20:52:56