我想在我的应用程序来创建输入文本字段,并确定和取消按钮的弹出窗口:Android的弹出窗口
这是我在MainActivity代码:
forgotPassword.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
View pview = inflater.inflate(R.layout.forgot_password_popup,(ViewGroup)findViewById(R.layout.login));
final PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.forgot_password_popup,(ViewGroup)findViewById(R.layout.login)));
pw.showAtLocation(v, Gravity.LEFT,0,0);
pw.update(8,-70,150,270);
//if onclick written here, it gives null pointer exception.
Button okbtn=(Button)pview.findViewById(R.id.okbtn);
Button cancelbtn = (Button)pview.findViewById(R.id.cancelbtn);
final EditText emailText = (EditText) pview.findViewById(R.id.EmailText);
okbtn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try {
ParseUser.requestPasswordReset(emailText.getText().toString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
cancelbtn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
pw.dismiss();
}
});
}
});
这里是我忘了password_popup .XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/EmailText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:hint="Enter Email Address"
android:inputType="textEmailAddress"
android:password="true"
android:singleLine="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/okbtn"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="OK" />
<Button
android:id="@+id/cancelbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
但它切断(我看不到文本字段或取消按钮,也没有任何背景的弹出窗口(我希望有一个透明背景)
而且,我不能点击确定按钮,这样有毛病我的代码
我会很高兴的帮助
这是它的样子:
http://img827.imageshack.us/img827/9545/capturehdv.png
非常感谢
http://developer.android.com/guide/topics/ui/dialogs.html – 2013-03-05 16:18:38
谢谢,我会看它,也,你知道如何创建它trasperanct?谢谢 – 2013-03-05 16:22:08
@AdirRahamim你尝试我发布的内容..? – Pragnani 2013-03-05 16:24:23