我想根据字符串值在 android 按钮视图中显示不同样式的按钮,我可以以编程方式执行此操作吗?
我可以以编程方式使用设置样式条件,即使我设置了 setTextAppearance 它没有反映在视图中吗?
private Button dynakey[]= new Button[9];//8 buttons
//Parse the values of buttons
try {
String sButtonString="";
JSONArray jArrayButton =
ResponseUIObject.getJSONArray("BUTTON");
for(int k=0;k<8;k++) {
int ID=k+1;
String dynakeyID = "dynakey"+(ID);
int resID = getResources().getIdentifier(dynakeyID, "id", getPackageName());
dynakey[ID] =(Button) findViewById(resID);
sButtonString= jArrayButton.getString(k-0);
//Set Enable or Disable logic here
if ((ID% 2) == 0) {
// number is even its a right side button //Change style of button depending upon the value
if(sButtonString.trim().length() == 0) {
//If string is not null or not empty then Enable the button else not
dynakey[ID].setTextAppearance(this, R.style.RightDisableDynakeyButton);
}else{
dynakey[ID].setTextAppearance(this, R.style.RightEnableDynakeyButton);
}
}
else {
// number is odd its a left side button //Change style of button depending upon the value
if(sButtonString.trim().length() ==0) {
//If string is not null or empty then Enable the button else not
dynakey[ID].setTextAppearance(this, R.style.LeftDisableDynakeyButton);
}else{
dynakey[ID].setTextAppearance(this, R.style.LeftEnableDynakeyButton);
}
}
}
}
收到一只叮咚
jeck猫
相关分类