This happens because of hierarchical order of your activity layout. Your ActionBar
is being drawn over your View. You can find your activity's frame and add the view there.
private void addCircleView() {
final FrameLayout frameLayoutRoot = (FrameLayout) getActivity().getWindow()
.getDecorView().findViewById(android.R.id.content);
View circleView = inflater.inflate(
R.layout.my_circle_view, frameLayoutRoot, false);
ViewGroup.MarginLayoutParams marginLayoutParams =
((ViewGroup.MarginLayoutParams) circleView.getLayoutParams());
marginLayoutParams.topMargin = getStatusBarHeight(getActivity())
+ getActivity().getActionBar().getHeight()
+ getResources().getDimensionPixelSize(R.dimen.your_margin_top_circle);
circleView.setLayoutParams(marginLayoutParams);
frameLayoutRoot.addView(circleView);
}
public int getStatusBarHeight(Context context) {
int result = 0;
final int resourceId = context.getResources().getIdentifier(
"status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
Also remember to remove the view when you navigate away to an other fragment.
frameLayoutRoot.removeView(circleView);
Edit:
Please note that this is something that you should be doing at the level that you add ActionBar
, which is the activity. In that case you wouldn't need these workarounds. This stuff are way more simple to achive with ToolBar
.