我正在使用带有自定义适配器的RecyclerView的Alert Dialog。
我试图实施:
AlertDialog alert = dialog.create();
alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
// alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
alert.show();
并在适配器类中显示键盘:
inputHoursEt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
}
});
还在清单文件中尝试过主要活动:
android:windowSoftInputMode="adjustResize"
编辑:
完整的对话代码:
private void openEnterResourceHoursDialog(int i, String selectedActivityId, String selectedActivityName) {
loader.dismiss();
Log.i(Constants.APP_NAME, "total resources : "+resourceListItems.size());
if (resourceListItems.size()>0){
final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
LayoutInflater factory = LayoutInflater.from(getActivity());
final View content = factory.inflate(R.layout.resource_dialog, null);
RecyclerView detailsRecyclerView = (RecyclerView) content.findViewById(R.id.resourceListRv);
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
detailsRecyclerView.setLayoutManager(llm);
llm.setOrientation(LinearLayoutManager.VERTICAL);
Button detailSubmitButton = (Button) content.findViewById(R.id.enterBtn);
Button detailsCloseButton = (Button) content.findViewById(R.id.cancelBtn);
TextView activityNameTv = (TextView) content.findViewById(R.id.activityNameTv);
activityNameTv.setText(selectedActivityName);
ResourceListAdapter detailsAdapter = new ResourceListAdapter(getActivity(), resourceListItems);
detailsRecyclerView.setAdapter(detailsAdapter);
dialog.setView(content);
dialog.setCancelable(false);
final AlertDialog alert = dialog.create();
alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE );
// alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
alert.show();
detailsCloseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alert.dismiss();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN,0);
}
});
detailSubmitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alert.dismiss();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN,0);
}
});
}else{
utils.showShortToast(getActivity(),"There is no resource");
}
}