The application logo is located half in the ActionBar and half on the mainActivty screen

Is it possible to do something similar in Android? I think this is not the case, since you can specify 2 different layouts, one for ActionBar and one for Activity, but I can also be wrong

enter image description here

+4
source share
1 answer

This is a much more solid solution than previously proposed PopupWindow.

The layout for overlaying the logo is a simple ImageViewone on which we set the attribute clickablein trueto prevent the transfer of touch events to the Viewbottom.

logo.xml layout:

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:scaleType="fitXY"
    android:src="@drawable/ic_launcher"
    android:clickable="true" />

ActionBar View . Toolbar View, , , , Toolbar - View, XML.

private void showLogoOverlay() {
    final View anchor = findViewById(android.R.id.home);
    if(anchor == null) {
        return;
    }

    final View overlay = getLayoutInflater().inflate(R.layout.logo, null, false);
    final ViewGroup decor = (ViewGroup) getWindow().getDecorView();

    anchor.addOnLayoutChangeListener(new OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right,
                                       int bottom, int oldLeft, int oldTop,
                                       int oldRight, int oldBottom) {

                int[] offset = new int[2];
                anchor.getLocationOnScreen(offset);

                decor.addView(overlay, 200, 200);
                overlay.setX(offset[0]);
                overlay.setY(offset[1]);

                anchor.removeOnLayoutChangeListener(this);
            }
        }
    );
}
+1

All Articles