dialog 全屏 透明度 无法弹出输入键盘
来源:互联网 发布:医院电子签名系统 源码 编辑:程序博客网 时间:2024/05/18 00:04
1.无法弹出输入键盘
有人说,不让我extends alertdialog
让我改写为dialog;
发现不行;
方法二:
1.解决无法弹出输入法:
在show()方法调用之前,用dialog.setView(new EditText(context))添加一个空的EditText,由于是自定义的AlertDialog,有我们指定的布局,所以设置这个不会影响我们的功能,这样就可以弹出输入法了……
看我的全能代码:
public class SearchContentDialog extends AlertDialog { private View.OnClickListener mListener; private Context mContext; private TextView tvwNetInfo; private ImageView mImageView; public Button mBtnLoad; private String content; private boolean isShowAgainLoad = true; private LinearLayout llBtnSearch; private EditText edtContent; private SearchContentListener searchContentListener; private InputMethodManager imm; public SearchContentDialog(Context context, String content, View.OnClickListener listener) { super(context); this.mContext = context; this.content = content; this.mListener = listener; this.setCanceledOnTouchOutside(false); } public SearchContentDialog(Context context, SearchContentListener searchContentListener) { super(context); this.mContext = context; this.searchContentListener = searchContentListener; this.setCanceledOnTouchOutside(false); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_search_content); edtContent = (EditText) findViewById(R.id.edt_search_content); imm = (InputMethodManager) mContext.getSystemService(INPUT_METHOD_SERVICE); edtContent.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { imm.showSoftInput(v, 0); } else { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } } }); edtContent.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_UNSPECIFIED) { LogUtils.e("sjt", "触发了搜索"); searchContentListener.searchByContent(edtContent.getText().toString()); return true; } return false; } }); llBtnSearch = (LinearLayout) findViewById(R.id.ll_search_content); TextView tvwCancle = (TextView) findViewById(R.id.tvw_cancle); tvwCancle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); llBtnSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { searchContentListener.searchByContent(edtContent.getText().toString()); } }); } @Override public void show() { super.show(); /** * 设置宽度全屏,要设置在show的后面 */ WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); layoutParams.gravity = Gravity.CENTER; layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT; getWindow().getDecorView().setPadding(0, 0, 0, 0); getWindow().setAttributes(layoutParams); } @Override public void onBackPressed() { Activity activity = (Activity) mContext; WindowManager.LayoutParams params = activity.getWindow().getAttributes(); params.alpha = 0.5f; activity.getWindow().setAttributes(params); activity.finish(); super.onBackPressed(); } public void showKeyboard() { if (edtContent != null) { //设置可获得焦点 edtContent.setFocusable(true); edtContent.setFocusableInTouchMode(true); //请求获得焦点 edtContent.requestFocus(); //调用系统输入法 InputMethodManager inputManager = (InputMethodManager) edtContent .getContext().getSystemService(INPUT_METHOD_SERVICE); inputManager.showSoftInput(edtContent, 0); } } public interface SearchContentListener { public void searchByContent(String content); }}
2.透明度问题
1.设置透明度(Dialog自身的透明度)
WindowManager.LayoutParams lp=dialog.getWindow().getAttributes();
lp.alpha=1.0f;
dialog.getWindow().setAttributes(lp);
alpha在0.0f到1.0f之间。1.0完全不透明,0.0f完全透明
2.设置黑暗度(Dialog自身的黑暗度)
dialog.setContentView(R.layout.dialog);
WindowManager.LayoutParams lp=dialog.getWindow().getAttributes();
lp.dimAmount=1.0f;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dimAmount在0.0f和1.0f之间,0.0f完全不暗,1.0f全暗
3.设置Dialog底背景模糊和黑暗度
WindowManager.LayoutParams.FLAG_BLUR_BEHIND(设置模糊)
WindowManager.LayoutParams.FLAG_DIM_BEHIND(设置暗淡)
4.清除Dialog底背景模糊和黑暗度
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND | WindowManager.LayoutParams.FLAG_DIM_BEHIND)
- dialog 全屏 透明度 无法弹出输入键盘
- Android 解决dialog无法弹出输入键盘
- 底部弹出全屏dialog
- android自定义dialog,软件键盘弹出挡住输入区域解决
- Android自定义dialog中的EditText无法弹出键盘的解决
- Android自定义dialog中的EditText无法弹出键盘的解决
- Android自定义dialog中的EditText无法弹出键盘的解决
- dialog中的EditText无法弹出输入框解决方法
- Android弹出输入键盘
- EditText无法输入内容,无法获得焦点,无法自动弹出键盘
- 设置Dialog全屏,并从底部弹出
- 底部弹出带输入dialog
- 解决Dialog中有EditText时无法自动弹出输入的问题
- 自定义Dialog宽度无法全屏的解决方案
- 弹出键盘 输入框上移
- Dialog中EditText不弹出键盘解决方案
- Android Fragment键盘无法弹出
- Xcode6.3模拟器ios8.3模拟器不能弹出虚拟键盘及虚拟键盘无法切换中文输入的解决办法
- 封装制作的一些注意事项
- xamarin学习笔记A18(安卓Service)
- 蓝桥杯 算法训练 表达式计算
- Android不透明度色值
- 个人电脑win7建立FTPfu
- dialog 全屏 透明度 无法弹出输入键盘
- Axure-制作App上下滑动效果
- 关于TreeMap的一些简单理解
- javascript 数组去重并统计原数组每个元素个数
- centos7安装FastDFS
- 加密(位运算)【20171116练习】
- 培训机构JavaScript各种基本函数的运用详解。
- 我眼中的Vue
- Linux常用命令