0

I wanna make coach marks for action buttons but I don't now how to get their positions and paddings on action bar. You can see what I have in mind but I cant reach in this picture:

enter image description here

I have a translucent overlay layout but I wanna show icons I'm describing in full transparency.

Is there any way to do that? Thanks in advance

EDIT: in fact these are the values I need to find since they are different in different devices

enter image description here

EDIT2: using Nigam Patro's solution, I ended up this:

enter image description here

code:

...
int[] filterPosition = new int[2];
findViewById(R.id.action_filter).getLocationOnScreen(filterPosition);
View filterDummy = coachMark.findViewById(R.id.filter_dummy);
filterDummy.setX(filterPosition[0]);
filterDummy.setY(filterPosition[1]);
...

layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/translucent"
    android:fitsSystemWindows="true"
    android:paddingBottom="@dimen/activity_vertical_margin" >

    <ImageView
        android:id="@+id/filter_dummy"
        android:layout_width="?android:attr/actionBarSize"
        android:layout_height="?android:attr/actionBarSize"
        android:padding="9dp"
        android:src="@drawable/ic_filter_false" />

</RelativeLayout

EDIT3: code:

...
int[] filterPosition = new int[2];
View filterView = findViewById(R.id.action_filter);
filterView.getLocationOnScreen(filterPosition);
int paddingTop = filterView.getPaddingTop();
int paddingBottom = filterView.getPaddingBottom();
int paddingLeft = filterView.getPaddingLeft();
int paddingRight = filterView.getPaddingRight();
View filterDummy = coachMark.findViewById(R.id.filter_dummy);
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
    statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
filterDummy.setX(filterPosition[0]);
filterDummy.setY(filterPosition[1] - statusBarHeight);
filterDummy.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
...

Result: enter image description here

Very close,but still not right

MamadTell
  • 163
  • 1
  • 12

1 Answers1

1

By the following you can get the view from the actionbar

findViewById(R.id.menu_item);

and by using this method you can get the view's X & Y position

View.getLocationOnScreen()

So, after getting the X & Y position get the height of status bar,

public int getStatusBarHeight() { 
      int result = 0;
      int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
      if (resourceId > 0) {
          result = getResources().getDimensionPixelSize(resourceId);
      } 
      return result;
} 

Now differentiate the Y with the statusbar height, you will get the original height y position of item inside activity.

X values is the left margin, Y value is top margin.

Nigam Patro
  • 2,760
  • 1
  • 18
  • 33