我正在实现一个简单的方法来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);
}
Run Code Online (Sandbox Code Playgroud)