开发遇到的low坑
16lz
2021-01-23
RadioGroup使用遇到的总结
指定RadioButton选中
RadioButton mainButton = (RadioButton) findViewById(R.id.rb_home_safety); mRadioGroup.check(mainButton.getID())
指定一个RadioButton页面
((RadioButton) mRadioGroup.findViewById(R.id.rb_home_safety)).setChecked(true);
取消所有RadioButton的选择状态
mRadioGroup.setOnCheckedChangeListener(null);mRadioGroup.clearCheck();mRadioGroup.setOnCheckedChangeListener(this);mPager.setCurrentItem(0);
点击手机返回键,让app退到后台
OnBackPressed(){ moveTaskBack(false)}
fragment异常 【java.lang.IllegalStateException: Fragment(XXFragment) not attached to Activity异常】
- 出现该异常,是因为Fragment的还没有Attach到Activity时,调用了如getResource()等,需要上下文Content的函数。解决方法,就是等将调用的代码写在OnStart()中。
- 之前增加一个判断isAdded()。 【推荐第二个】
AlertDialog位于底部 全屏
View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_currency,null); AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.Dialog); final AlertDialog alertDialog = builder.setView(inflate).create(); alertDialog.setCancelable(true); alertDialog.show(); Window window = alertDialog.getWindow(); window.setGravity(Gravity.BOTTOM); WindowManager m = getWindowManager(); Display d = m.getDefaultDisplay(); //为获取屏幕宽、高 android.view.WindowManager.LayoutParams params = alertDialog.getWindow().getAttributes(); //获取对话框当前的参数值、 params.width = (int) (d.getWidth()); //宽度设置全屏宽度 alertDialog.getWindow().setAttributes(params); //设置生效
更多相关文章
- 【Android 电量优化】电量优化 ( 网络状态获取 | 主动获取 WIFI
- 第一行代码-9.6 服务的最佳实践--后台执行的定时任务
- Android状态栏提醒(Notification,NotificationManager)的使用!
- Android WebView内容宽度自适应
- Android通过JSON数据格式和java服务后台进行数据交互
- android之后台线程(UI与线程交互)