android-actionbar icon indicating copy to clipboard operation
android-actionbar copied to clipboard

Item drawables too large

Open nickdaugherty opened this issue 14 years ago • 3 comments

The action bar item drawable icons are all appearing full height/width for me (they stretch to fill the height of the actionbar), rather than the smaller image with padding that is seen in the example.

Is this an xml thing? I took the code from the example nearly verbatim.

nickdaugherty avatar Nov 29 '11 18:11 nickdaugherty

There's no magic going on, you have to assign an already scaled icon to the action.

johannilsson avatar Nov 30 '11 08:11 johannilsson

I see, thanks. Would be a nice feature if ActionBar auto scaled drawables to fit nicely.

nickdaugherty avatar Nov 30 '11 17:11 nickdaugherty

SOLVED:

Go to ActionBar.java in the library and change the inflateAction function to this:

private View inflateAction(Action action) { View view = mInflater.inflate(R.layout.actionbar_item, mActionsView, false);

    ImageButton labelView =
        (ImageButton) view.findViewById(R.id.actionbar_item);
    Drawable dr = getResources().getDrawable(action.getDrawable());
    dr.setBounds(labelView.getLeft(), labelView.getTop(), labelView.getRight(), labelView.getBottom());
    labelView.setBackgroundDrawable(dr);


    view.setTag(action);
    view.setOnClickListener(this);
    return view;
}

GuyWhoCodez avatar May 29 '13 20:05 GuyWhoCodez