Tronum
Tronum

Reputation: 717

Fragment on top android ActionBar

I have a Fragment with ImageView. How I can show this Fragment on top system android ActionBar?

For: Wottah ActionBar should be visible. It is necessary that the overlap would be my piece of it. We need to use something on this:

ImageView view = new ImageView (getActivity ());
view.setBackgroundColor (Color.GREEN); 
WindowManager.LayoutParams p = new WindowManager.LayoutParams (); 
p.gravity = Gravity.TOP;
p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; 
p.token = view.getWindowToken (); 
WindowManager mWindowManager = (WindowManager) getActivity (). GetSystemService(Context.WINDOW_SERVICE); 
mWindowManager.addView (view, p);

Upvotes: 2

Views: 1606

Answers (2)

Tronum
Tronum

Reputation: 717

Wottah, unfortunately your answer did not help. I looked up the source files of the android popupwindow and their decision to apply in my project.

The task: we have application. And standart android actionbar that (as we know) is a separate part of the application and my view may not be evidence on top of it.

The solution of the following: My view:

private class MyView extends ImageView
{
    public MyView(Context context)
    {
        super(context);
    }

    //it must be override
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            activity.onBackPressed();
        }
        return super.onKeyDown(keyCode, event);
    }
}

How do I use it:

private void createMyView()
    {
        view = new MyView(activity.getBaseContext());
        view.setBackgroundResource(R.drawable.*******);
        WindowManager mWindowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
        WindowManager.LayoutParams p = new WindowManager.LayoutParams();
        p.width = iconWidth;
        p.height = iconHeight;
        p.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
        p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
        p.token = view.getWindowToken();
        p.gravity = Gravity.TOP;
        p.x = x;
        p.format = PixelFormat.TRANSLUCENT;
        mWindowManager.addView(view, p);

        view.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //TODO
            }
        });
    }

Upvotes: 1

Wottah
Wottah

Reputation: 320

If you adapt your layout style you can hide the action bar, that way you dont need any weird constructions to put an ImageView on top of it.

Upvotes: 0

Related Questions