0

我正在制作一个警报对话框,并希望在屏幕的最顶部显示它(它的高度应该从最顶部开始)。我该怎么做?这是代码:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
m_rb10Minutes = new RadioButton(this);
            m_rb10Minutes.setText("10 minutes");
            m_rb20Minutes = new RadioButton(this);
            m_rb20Minutes.setText("20 minutes");
            m_rb30Minutes = new RadioButton(this);
            m_rb30Minutes.setText("30 minutes");
LinearLayout linearLayout = new LinearLayout(this);
            linearLayout.setBackgroundColor(getResources().getColor(R.color.black));
            linearLayout.setLayoutParams( new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT));
            linearLayout.setOrientation(1);  

            linearLayout.addView(m_rb10Minutes);
            linearLayout.addView(m_rb20Minutes);
            linearLayout.addView(m_rb30Minutes);
            alertTimer = alertDialog.create();
            alertTimer.setView(linearLayout);

            alertTimer.requestWindowFeature((int) Window.FEATURE_NO_TITLE);
            WindowManager.LayoutParams WMLP = alertTimer.getWindow().getAttributes();

            WMLP.x = 0;   //x position
            WMLP.y = 0;   //y position

            alertTimer.getWindow().setAttributes(WMLP);

            alertTimer.show();
4

1 回答 1

1

使用以下代码

    private CharSequence[] items = {"Set as Ringtone", "Set as Alarm"};
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setItems(items, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int item) {

        if(item == 0) {

        } else if(item == 1) {

        } else if(item == 2) {

        }
    }
    });

 AlertDialog dialog = builder.create();
 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
 WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();


WMLP.x = 100;   //x position
  WMLP.y = 100;   //y position

    dialog.getWindow().setAttributes(WMLP);

   dialog.show();
于 2012-08-19T10:27:31.980 回答