我實現一個簡單的方法來添加一個Button
到LinearLayout
編程。Button.setBackground(可繪製背景)拋出的NoSuchMethodError
當我調用的setBackground(可繪製背景)方法,下面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);
}
那麼,什麼是添加解決方案按鈕的背景編程方式低於Api 16..withou t setBackGroundDrawable ..這是不贊同......? –
@EslamYousefMohammed編輯我的回答:嘗試'setBackgroundResource'。 – Mena
我已經設置安卓的minSdkVersion =「9」在我的清單,爲什麼犯規蝕提醒我有關? – wutzebaer