Android:键盘打开时隐藏导航栏

时间:2016-08-22 16:14:17

标签: android

我有一个在包含多个EditTexts的服务中启动的对话框。我的问题是,当EditText获得焦点时,键盘会出现,导航栏会消失。有没有办法阻止导航栏消失?

这是对话框代码(来自服务内部):

@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
    final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    _view = inflater.inflate(R.layout.dialog_notif, null);

    _edit_1 = (EditText) _view.findViewById(R.id.edit1);
    _edit_2 = (EditText) _view.findViewById(R.id.edit2);

    _dial = new Dialog(this);
    _dial.requestWindowFeature(Window.FEATURE_NO_TITLE);
    _dial.getWindow().setBackgroundDrawable(new ColorDrawable(0x66000000));
    _dial.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
    _dial.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    _dial.setContentView(_view);
    _dial.setCanceledOnTouchOutside(false);
    _dial.setOnDismissListener(new DialogInterface.OnDismissListener()
    {
        @Override
        public void onDismiss(DialogInterface dialogInterface)
        {
            stopSelf();
        }
    });
    _dial.show();

    return START_STICKY;
}

这就是它的样子:

Before and After: Navigation Bar Hidden by Keyboard

1 个答案:

答案 0 :(得分:1)

您正在使用Dialog的上下文创建Service

_dial = new Dialog(this);

强烈推荐。您的导航栏可能因Dialog的主题/样式而隐藏。考虑开始新的Activity,其中包含custom dialog-like-style