Android 当键盘在片段中打开时,警报对话框不向上移动

Android 当键盘在片段中打开时,警报对话框不向上移动,android,android-layout,Android,Android Layout,我在fragment中动态创建了一个警报对话框。该对话框有一个编辑文本和一个按钮。当用户将焦点放在编辑文本键盘上并打开其隐藏对话框按钮时,我的问题是。而我的对话框没有移到顶部 private void AlertEditMode(final MyIshVo myIshVo) { final LinearLayout linearLayout=new LinearLayout(getContext()); final EditText edittext = new EditText

我在fragment中动态创建了一个警报对话框。该对话框有一个编辑文本和一个按钮。当用户将焦点放在编辑文本键盘上并打开其隐藏对话框按钮时,我的问题是。而我的对话框没有移到顶部

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);

}
但这两种解决方案都不起作用。任何其他解决方案请提前提出,谢谢


[![check image][1]][1]

如果要在顶部显示对话框,请在下面的代码中使用

    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.requestWindowFeature(Window.FEATURE_NO_TITLE);
    WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();

    wmlp.gravity = Gravity.TOP | Gravity.LEFT;
    wmlp.x = 100;   //x position
    wmlp.y = 100;   //y position

    dialog.show();
    // dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

}
private void AlertEditMode(最终MyIshVo MyIshVo){
final LinearLayout LinearLayout=新的LinearLayout(getContext());
final EditText EditText=新的EditText(getContext());
LinearLayout.LayoutParams LayoutParams=新的LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_内容,LinearLayout.LayoutParams.WRAP_内容);
layoutParams.setMargins(50,0,50,0);
edittext.setLayoutParams(layoutParams);
linearLayout.addView(编辑文本);
final AlertDialog dialog=新建AlertDialog.Builder(getContext())
.setView(线性布局)
.setTitle(“即时共享”)
.setPositiveButton(android.R.string.ok,null)//设置为null。我们重写onclick
.setNegativeButton(android.R.string.cancel,null)
.create();
//relativeLayout.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT\u INPUT\u ADJUST\u PAN);
edittext.setText(myIshVo.getMish_name());
edittext.setSelection(edittext.getText().length());
dialog.setOnShowListener(新的DialogInterface.OnShowListener(){
@凌驾
公共void onShow(最终对话框界面对话框){
按钮按钮=((AlertDialog)对话框).getButton(AlertDialog.Button_正);
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
String ish_title=edittext.getText().toString().trim();
字符串instant_share_Id=myIshVo.getMinstant_share_Id();

如果(ish|u title==null | | ish|title.equalsIgnoreCase(“”)| | ish|title.contains(“当显示
警报对话框
活动具有半透明状态栏主题时,我遇到了此问题

因此,我没有使用经典的
AlertDialog.builder(context)
初始化构建器,而是显式地向其传递一个没有半透明状态栏的对话框主题:

AlertDialog.Builder(context, android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar)

我选择这个主题是因为它可以确保与棒棒糖前的设备兼容,但是像android.R.style.theme\u Material\u Dialog这样的其他主题也应该做到这一点。

共享你的清单文件这是我的活动清单代码是否可以附加UI的屏幕截图。
软输入\u ADJUST\u PAN
这将work@Wizard我已更改为调整平移,但它不起作用。请查看您的答案。这可能不是我要找的…我的问题是当我打开键盘时…对话框应自动滑动到顶部。这段时间用于编辑文本框设置聚焦更改侦听器方法并根据设置代码放置对话框。建议的主题似乎是我想要的ed…一些基本和可靠的东西。感谢完美的解决方案。
AlertDialog.Builder(context, android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar)