gpt4 book ai didi

android - 设置宽度时我的自定义对话框没有出现

转载 作者:行者123 更新时间:2023-11-30 02:39:04 28 4
gpt4 key购买 nike

final Dialog dialog = new Dialog(MainScreenActivity.this);

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

dialog.setContentView(R.layout.activity_ana_ekran_dialog);
dialog.setCanceledOnTouchOutside(true);

Display display = getWindow().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
WindowManager.LayoutParams params = getWindow().getAttributes();
params.width = width * 90 / 100;
dialog.getWindow().setAttributes(params);

dialog.show();

此代码位于 onOptionsItemSelected 部分,当我按下操作栏按钮时,我的自定义对话框没有出现。

当我设置它的宽度时,我的自定义对话框没有出现?

最佳答案

我解决了这个问题,这是我解决它的方式...

Costume Dialog 类 public class HarcamaKayitDialog extends Dialog implements android.view.View.OnClickListener

变量

Context ctx;
EditText yorum;
EditText harcama;
Button buttonTamamDialog;
Button buttonIptalDialog;
Dialog dialog;

构造函数

   public HarcamaKayitDialog(Context context){
super(context);
this.ctx = context;
this.dialog = this;
}

创建时。

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_ana_ekran_alert_dialog);
Display display = getWindow().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
WindowManager.LayoutParams params = getWindow().getAttributes();
params.width = width * 90 / 100;
getWindow().setAttributes(params);
findViews();

}

点击。

    @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.buttonTamam:

//transactions

dialog.dismiss();
break;
case R.id.buttonIptal:
dialog.dismiss();

break;
default:
break;
}
}

findViews 函数。

private void findViews() {
yorum = (EditText) findViewById(R.id.editTextYorum);
harcama = (EditText) findViewById(R.id.editTextHarcama);
buttonTamamDialog = (Button) findViewById(R.id.buttonTamam);
buttonIptalDialog = (Button) findViewById(R.id.buttonIptal);
buttonTamamDialog.setOnClickListener(this);
buttonIptalDialog.setOnClickListener(this);

}

关于android - 设置宽度时我的自定义对话框没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26038857/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com