我已经在片段中动态创建了一个警告对话框.它有一个编辑文本和一个按钮.我的问题是当用户专注于编辑文本键盘打开时,它的隐藏对话框按钮.我的对话框没有移动到顶部. private void Al
private void AlertEditMode(final MyIshVo myIshVo) { final LinearLayout linearLayout=new LinearLayout(getContext()); final EditText edittext = new EditText(getContext()); LinearLayout.LayoutParams layoutParams =new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(50,0,50,0); edittext.setLayoutParams(layoutParams); linearLayout.addView(edittext); final AlertDialog dialog = new AlertDialog.Builder(getContext()) .setView(linearLayout) .setTitle("Instant Share") .setPositiveButton(android.R.string.ok, null) //Set to null. We override the onclick .setNegativeButton(android.R.string.cancel, null) .create(); // relativeLayout.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); edittext.setText(myIshVo.getMish_name()); edittext.setSelection(edittext.getText().length()); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(final DialogInterface dialog) { Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String ish_title = edittext.getText().toString().trim(); String instant_share_Id=myIshVo.getMinstant_share_Id(); if(ish_title==null || ish_title.equalsIgnoreCase("") || ish_title.contains("<") || ish_title.contains("\\") ){ //showToastMessage("Title should not be Empty"); edittext.setError("Please enter valid title."); }else{ presenter.setEditIsh(ish_title,instant_share_Id); dialog.dismiss(); } } }); } }); dialog.show(); // dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); }
我已经尝试将adjustresize赋予活动并动态给出
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
但这两种解决方案都不起作用.其他解决方案请提前表示感谢.
[![查看图片] [1]] [1]
当显示AlertDialog的Activity具有半透明状态栏主题时,我遇到了这个问题.因此,不是使用使用上下文主题的经典AlertDialog.Builder(context)初始化构建器,而是显式传递没有半透明状态栏的对话框主题:
AlertDialog.Builder(context, android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar)
我选择了这个主题,因为它确保了与棒棒糖前设备的兼容性,但是像android.R.style.Theme_Material_Dialog这样的其他设备也可以做到这一点.