I am creating a simple toolbar using RelativeLayout
and to a button image i am using following code,
ImageButton back = new ImageButton(ctx.getContext());
RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
backLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
back.setLayoutParams(backLayoutParams);
back.setContentDescription("Back Button");
back.setId(2);
try {
back.setImageBitmap(loadDrawable("icon_left.png"));
} catch (IOException e) {
Log.e(LOG_TAG, e.getMessage(), e);
}
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//
}
});
for adding it to the toolbar
toolbar.addView(back);
for toolbar i am using,
RelativeLayout toolbar = new RelativeLayout(ctx.getContext());
toolbar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,60));
Problem is that the button image doesnt FILLS inside layout param.
i tried using setMargin it works, but it doesnot scales with various screen resolutions.

Need directions on how to do this.
By default,
ImageButtonhas a button background behind its image just likeButtondoes behind its text.Disable the background by calling
setBackgroundDrawable(null)in your code.