你好我有很多按钮与OnClickListener相同,按钮有不同的颜色,我怎样才能获得按下按钮的颜色(或颜色资源)?android获取颜色
这里是我的代码使用
// declare a OnClickListener that will execute different actions
// depending on the view that was clicked
View.OnClickListener colorButtonListener = new View.OnClickListener(){
public void onClick (View v){
textarea_note.setBackgroundDrawable(v.getBackground());//set edit background the same of the button
dialog.dismiss();
}
};
Button button1 = (Button) dialog.findViewById(R.id.button1);
Button button2 = (Button) dialog.findViewById(R.id.button2);
Button button3 = (Button) dialog.findViewById(R.id.button3);
Button button4 = (Button) dialog.findViewById(R.id.button4);
Button button5 = (Button) dialog.findViewById(R.id.button5);
Button button6 = (Button) dialog.findViewById(R.id.button6);
Button button7 = (Button) dialog.findViewById(R.id.button7);
Button button8 = (Button) dialog.findViewById(R.id.button8);
Button button9 = (Button) dialog.findViewById(R.id.button9);
/*for changing the colour when the user clicks on a button*/
button1.setOnClickListener(colorButtonListener);
button2.setOnClickListener(colorButtonListener);
button3.setOnClickListener(colorButtonListener);
button4.setOnClickListener(colorButtonListener);
button5.setOnClickListener(colorButtonListener);
button6.setOnClickListener(colorButtonListener);
button7.setOnClickListener(colorButtonListener);
button8.setOnClickListener(colorButtonListener);
button9.setOnClickListener(colorButtonListener);
/**for the round corner*/
Resources res = this.getResources();
button1.setBackgroundDrawable(this.Sd(res.getColor(R.color.color1x1)));
button2.setBackgroundDrawable(this.Sd(res.getColor(R.color.color1x2)));
button3.setBackgroundDrawable(this.Sd(res.getColor(R.color.color1x3)));
button4.setBackgroundDrawable(this.Sd(res.getColor(R.color.color2x1)));
button5.setBackgroundDrawable(this.Sd(res.getColor(R.color.color2x2)));
button6.setBackgroundDrawable(this.Sd(res.getColor(R.color.color2x3)));
button7.setBackgroundDrawable(this.Sd(res.getColor(R.color.color3x1)));
button8.setBackgroundDrawable(this.Sd(res.getColor(R.color.color3x2)));
button9.setBackgroundDrawable(this.Sd(res.getColor(R.color.color3x3)));
//now that the dialog is set up, it's time to show it
dialog.show();
你有mispeled错误?是的,但一旦我有Drawable如何提取颜色的字符串形式,或颜色ID或任何我可以用来保存到文件和读取和应用到EditText,谢谢 – max4ever 2011-05-18 10:14:04
拼写错误是无用的,你可以禁用它。现在使用:你可以保存可绘制文件本身,并将其设置为任何你想要的视图的背景。但是我担心你可以从这个可绘制对象中获取颜色标识或任何字符串形式。 – mudit 2011-05-18 10:29:10
你的意思是“你不能得到颜色ID或...”或你“可以得到颜色ID或...” – max4ever 2011-05-18 10:35:56