我使用的使用创造了一个按钮下面code
I am using a button created using following code
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
Button btn = new Button(this);
btn.setOnClickListener(newtodobtn);
btn.setText("New Todo");
btn.setBackgroundDrawable(new Button(this).getBackground());
ll.addView(btn);
我在路径 @绘制/ new_todo_image
图片设置为背景的按钮。如何将其设置为按钮编程?
I have an image in path @drawable/new_todo_image
to set as background for the button. How to set it to the button programmatically?
有关设置背景图片的按钮,这是在绘制的文件夹,然后用低于code
for set background image for button which is in drawable folder then use below code
btn.setBackgroundResource(R.drawable.new_todo_image);