ume*_*sth 4 android android-layout
我已经动态创建了一个警报对话框,其中有一个编辑文本和一个按钮。我的问题是当用户将重点放在编辑文本键盘上并隐藏对话框按钮时,我的对话框没有移到顶部。
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);
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过给adjustresize活动并动态地给
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Run Code Online (Sandbox Code Playgroud)
但两种解决方案均无法使用。其他解决方案请先提出建议。
[![检查图片] [1]] [1]
我已经在这个问题上Activity,其中AlertDialog被显示为具有半透明的状态条的主题。
因此AlertDialog.Builder(context),我没有使用使用上下文主题的经典字体来初始化构建器,而是显式传递了一个不带半透明状态栏的对话框主题:
AlertDialog.Builder(context, android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar)
Run Code Online (Sandbox Code Playgroud)
我选择这个主题是因为它可以确保与棒棒糖之前的设备兼容,但是其他类似的工具android.R.style.Theme_Material_Dialog也可以做到这一点。
小智 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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
643 次 |
| 最近记录: |