当显示键盘时,我的Android AlertDialog没有向上移动
因此,当按下按钮时,我会在活动中调用一个警报对话框:当显示键盘时,我的Android AlertDialog没有向上移动,android,keyboard,alert,dialog,Android,Keyboard,Alert,Dialog,因此,当按下按钮时,我会在活动中调用一个警报对话框: Button editLocation = (Button) itemView.findViewById(R.id.edit_trained_location_button); editLocation.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showEditLocationDia
Button editLocation = (Button) itemView.findViewById(R.id.edit_trained_location_button);
editLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showEditLocationDialog();
}
});
public void showEditLocationDialog(){
LayoutInflater inflater = activity.getLayoutInflater();
AlertDialog.Builder builder =
new AlertDialog.Builder(activity, R.style.AppTheme);
builder.setTitle("Edit Location name");
builder.setPositiveButton("Save", null);
builder.setNegativeButton("Cancel", null);
builder.setView(inflater.inflate(R.layout.location_dialog, null));
Window newLocationDialog = builder.show().getWindow();
newLocationDialog.setLayout(DpToPxHelper.convertToPx(350, activity),
DpToPxHelper.convertToPx(175, activity));
newLocationDialog.setDimAmount(.8f);
newLocationDialog.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
这是布局文件的一个示例
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:isScrollContainer="false"
android:id="@+id/location_name_edit_text"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"/>
</LinearLayout>
(按钮在生成器中定义,布局仅允许我创建EditText字段)
因此,我的问题是,当我打开键盘将文本输入EditText字段时,对话框没有向上推,因此底部的按钮被阻止:
奇怪的是对话里面的文字被推上了…但窗口没有:(
我所尝试的:
我已经将其添加到manifest.xml中,并观察到它仍然没有向上移动对话框
我也尝试过,但仍然没有效果getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT\u INPUT\u ADJUST\u PAN);
我也尝试过,如果运气不好,同样的行为也会发生,对话不会向上移动,但里面的文本会向上推使用构造器生成器(活动…(没有主题)成功了!我猜是因为它从该活动中获取了主题设置。添加到这个答案,因为它似乎是与相同的问题,重要的是,提供给生成器的主题不应该有半透明的状态栏。