我正在实现一个简单的方法,通过程序将 Button
添加到 LinearLayout
中。
当我调用 setBackground(Drawable background)
方法时,会抛出以下 Error
:
java.lang.NoSuchMethodError: android.widget.Button.setBackground
我的 addNewButton 方法:
private void addNewButton(Integer id, String name) {
Button b = new Button(this);
b.setId(id);
b.setText(name);
b.setTextColor(color.white);
b.setBackground(this.getResources().getDrawable(R.drawable.orange_dot));
//llPageIndicator is the Linear Layout.
llPageIndicator.addView(b);
}