Saeid
Saeid

Reputation: 2321

Icon or image in actionbar

i need to make icon(imageview) inside actionbar that have shown half of image inside actionbar and other half show in screen(layout) like below image:

enter image description here

one idea is a image that have a transparent under below of color but when i set background this image for actionbar , image deform, and if i make actionbar height , layout size will small

now what i should to do for resolving this problem?

Upvotes: 2

Views: 170

Answers (1)

jvincek
jvincek

Reputation: 580

As far as I know, you cannot add a View to the ActionBar and achieve this, because a View cannot go beyond the limits of it's parent (container) - in this case the ActionBar. One thing you could to is add this ImageView to the decor view, which is a parent to both the ActionBar and the Activity (Fragment) layout. Example (from your Activity, for example in onPostCreate()):

ViewGroup decor = (ViewGroup) getWindow().getDecorView();
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customLayout = inflater.inflate(R.layout.my_layout, null);
// find views in customLayout, add click listeners etc.
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// add margins, gravity, etc. to this LayoutParams
decor.addView(imageView, params);

Upvotes: 1

Related Questions