w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
programmatically put an Image button inside custom buttons of table layout

Try this-

LinearLayout ll =
(LinearLayout)findViewById(R.id.linearLayout2);
ImageButton b = new ImageButton(this);
b.setText("ImageButton");
b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
b.setId(MY_BUTTON);
i1Btn = R.drawable.image_name;
i1.setImageResource(i1Btn);
b.setOnClickListener(this);
ll.addView(b);

Or other way create button with image in background-

LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
Button btn = new Button(this);
btn.setOnClickListener(this);
btn.setText("New Todo");
btn.setBackgroundResource(R.drawable.image_name);
ll.addView(btn);




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.