我正在尝试创建一个用户主题的应用程序。我有可点击的线性布局,当布局添加到父视图时,我需要以编程方式设置选择器。但是,当我设置 v.SetBackground() 时,以下代码会引发 NoSuchMetod 异常。
我哪里错了?
LinearLayout d = (LinearLayout) inflater.inflate(R.layout.adapter_psudo_launcheritem, null);
ColorDrawable clrBase = new ColorDrawable();
clrBase.setColor(gCurrentTheme.Colours.Backgrounds.MenuItem);
ColorDrawable clrSelect = new ColorDrawable();
clrSelect.setColor(gCurrentTheme.Colours.Backgrounds.MenuItem_Select);
ColorDrawable clrPress = new ColorDrawable();
clrPress.setColor(gCurrentTheme.Colours.Backgrounds.MenuItem_Press);
StateListDrawable states = new StateListDrawable();
states.addState(new int[] {android.R.attr.state_enabled}, clrBase);
states.addState(new int[] {android.R.attr.state_selected}, clrSelect);
states.addState(new int[] {android.R.attr.state_pressed}, clrPress);
//This line causes a NoSuchMethod exception!
v.setBackground(states);