如何从警报对话框中删除剩余的灰色窗口

时间:2013-07-30 12:58:10

标签: android background dialog window alertdialog

我创建了一个 alertdialog 弹出窗口,允许人们改变我正在制作的游戏的难度。

不幸的是,当我点击 ok,取消或在对话框之外时,背景标题窗口显示而不是返回到主屏幕。

我必须点击一个额外的时间才能删除背景标题窗口。

如何完全删除它,以便当用户完成更改难度时,他们会直接返回菜单而不是标题窗口?

我尝试使用

requestWindowFeature(Window.FEATURE_NO_TITLE);

但它不会删除该框。

以下是重要的代码:

爪哇:

public class Difficulty extends Activity{

final CharSequence[] items = {"Easy", "Medium", "Hard"};
int daf;
AlertDialog diffMode;
String diff = "DifficultyMode";
String howHard;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    SharedPreferences settings = getSharedPreferences(diff,0);      
    daf = settings.getInt("num",0);     
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Difficulty");
    builder.setSingleChoiceItems(items, daf, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int item) {


        switch(item)
        {
            case 0:
                daf = 0;
                howHard = "Easy";
                     break;
            case 1:
                daf = 1;
                howHard = "Medium";

                    break;
            case 2:
                daf = 2;
                howHard = "Hard";
                    break;

        }
          }
    });

    builder.setPositiveButton("ok", new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int id){
            SharedPreferences setting = getSharedPreferences(diff,0);
            SharedPreferences.Editor editor = setting.edit();
            editor.putString("mode", howHard);
            editor.putInt("num", daf);
            editor.commit();
            diffMode.dismiss();    
        }
    });

    builder.setNegativeButton("cancel", new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int id){
            diffMode.dismiss();    
        }
    });
    diffMode = builder.create();
    diffMode.show();
}
}

清单:

<activity
        android:name=".Difficulty"
        android:label="@string/app_name"             
       android:theme = "@android:style/Theme.Dialog"
      >
        <intent-filter>
            <action android:name="com.tnalcove.blindpick.DIFFICULTY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity> 

我无法发布图片所以这里是一张专辑的链接 http://imgur.com/a/IUJJW

0 个答案:

没有答案