android 2.2 无法使用:setCompoundDrawablesRelativeWithIntrinsicBounds
错误代码:
FATAL EXCEPTION: main
java.lang.NoSuchMethodError: android.widget.RadioButton.setCompoundDrawablesRelativeWithIntrinsicBounds
at com.vkoov.zjth.LatestActivity01.onResume(Unknown Source)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
at android.app.Activity.performResume(Activity.java:3823)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:170)
at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:518)
at android.app.ActivityGroup.onResume(ActivityGroup.java:58)
at com.vkoov.YaloeActivity.onResume(Unknown Source)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
at android.app.Activity.performResume(Activity.java:3823)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3143)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2684)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
解决办法:
int sysVersion = Integer.parseInt(VERSION.SDK);
if (sysVersion < 14) {
drawable.setBounds(0, 0, 30,30);
((RadioButton) (getParent().findViewById(R.id.main_tab_zjth)))
.setCompoundDrawables(null, drawable, null, null);
} else {
((RadioButton) (getParent().findViewById(R.id.main_tab_zjth)))
.setCompoundDrawablesRelativeWithIntrinsicBounds(null,
drawable, null, null);
}
setCompoundDrawablesRelativeWithIntrinsicBounds