ラジオボタンの色を設定しようとしています。コードにエラーはなく、問題のないさまざまなデバイス(API => 22)でアプリを実行できますが、特定のデバイス(API 16)ではアプリがクラッシュし、次のデバッグエラーが発生します:設定ボタンの色合いリストに関するランタイムエラー
java.lang.NoSuchMethodErrorの:android.widget.CompoundButton.setButtonTintList
私はコードのセクションで任意の明白な問題を参照することはできません(下記添付)すべてのヘルプははるかになるAPI 16によって影響されるだろう感謝。
CompoundButton t;
t = new CheckBox(context);
int[][] states = new int[][] {
new int[] { android.R.attr.state_enabled}, // enabled
new int[] {-android.R.attr.state_enabled}, // disabled
new int[] {-android.R.attr.state_checked}, // unchecked
new int[] { android.R.attr.state_pressed} // pressed
};
int[] colors = new int[] {
Color.BLACK,
Color.RED,
Color.GREEN,
Color.BLUE
};
ColorStateList c = new ColorStateList(states, colors);
t.setButtonTintList(c);
はい、下位のAPI(API <21)ではこのメソッドは使用できませんので、コードを変更してください...それは動作します –
今すぐ調べてください –