HI我有一个游戏关卡屏幕..当触摸关卡时,我需要为其提供指令提示/弹出窗口(可缩放)。Android-如何创建自定义对话框/提醒
应该customized..likes在愤怒鸟弹出..
自己的背景图像 没有国界 只有OK按钮
请帮我我将要发布这GOOGLEPLAY ...
HI我有一个游戏关卡屏幕..当触摸关卡时,我需要为其提供指令提示/弹出窗口(可缩放)。Android-如何创建自定义对话框/提醒
应该customized..likes在愤怒鸟弹出..
自己的背景图像 没有国界 只有OK按钮
请帮我我将要发布这GOOGLEPLAY ...
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch (id) {
case 0:
final Dialog mDialog = new Dialog(this);
mDialog.setContentView(R.layout.customdialog);
mDialog.setTitle("Custom Dialog");
mDialog.show();
mDialog.setCancelable(false);
final EditText txtUser = (EditText)mDialog.findViewById(R.id.txtUserName);
Button btnButtonOK = (Button)mDialog.findViewById(R.id.btnOK);
Button btnButtonCancel = (Button)mDialog.findViewById(R.id.btnCancel);
btnButtonOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String user = txtUser.getText().toString();
if (!user.equals(""))
{
Toast.makeText(getApplicationContext(),
user, Toast.LENGTH_LONG).show();
mDialog.dismiss();
}
}
});
btnButtonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mDialog.dismiss();
}
});
break;
}
,你可以让你的奥尼德兴有: progress_layer-XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/layer_folien"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/layer_gesamnt"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/dialog_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/layer_button" />
</LinearLayout>
和德代码来调用它
final Dialog dialog = new Dialog(PechaKuchaTimerActivity.this);
dialog.show();
final ProgressBar pr_fol = (ProgressBar) dialog.findViewById(R.id.progressBar1);
final ProgressBar pr_ges = (ProgressBar) dialog.findViewById(R.id.progressBar2);
final Button button_layerCancel = (Button) dialog.findViewById(R.id.dialog_cancel);
我认为你需要的代码这里是一个
mydialog.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" >
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:layout_gravity="center"
/>
</LinearLayout>
。
Dialog dialog=new Dialog(mContext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.mydialog);
dialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialogbackground);
Button mOkButton=(Button)dialog.findViewById(R.id.ok);
mOkButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//do here what you want to do with ok button click
}
});
这里dialogbackground
是背景图像
在这里它没有添加背景iaage ryte?需要一个背景图片... –
@ user972890 \t 在代码中添加了dialog.getWindow()。setBackgroundDrawableResource(R.drawable.dialogbackground);在这种情况下,dialogbackground是图像名称 – Akram
添加的组件是XML文件。 –
@ user972890按照这个http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235 – Akram