RadioGroup使用遇到的总结
RadioButton mainButton = (RadioButton) findViewById(R.id.rb_home_safety)
mRadioGroup.check(mainButton.getID())
((RadioButton) mRadioGroup.findViewById(R.id.rb_home_safety)).setChecked(true)
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)
<style name="Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowFullscreen">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>