Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Instead of creating your own button, just move the build in button according to the action bar size. <br> This code works for me and the button is just where the button should be (like in google maps): <br><br></p> <pre><code>// Gets the my location button View myLocationButton = getSherlockActivity().findViewById(R.id.MainContainer).findViewById(2); // Checks if we found the my location button if (myLocationButton != null){ int actionBarHeight = 0; TypedValue tv = new TypedValue(); // Checks if the os version has actionbar in it or not if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB){ if (getSherlockActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics()); } // Before the action bar was added to the api else if(getSherlockActivity().getTheme().resolveAttribute(com.actionbarsherlock.R.attr.actionBarSize, tv, true)){ actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics()); } // Sets the margin of the button ViewGroup.MarginLayoutParams marginParams = new ViewGroup.MarginLayoutParams(myLocationButton.getLayoutParams()); marginParams.setMargins(0, actionBarHeight + 20, 20, 0); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); myLocationButton.setLayoutParams(layoutParams); } </code></pre> <p><br> Just put this code in the onActivityCreated (if you will put it in the onCreateOptionsMenu, it will not support version before 3.0 - because the life cycle there is different. <br>Another thing, the "R.id.MainContainer" is the container of the map fragment. <br><br> I'm using ActionBar Sherlock, but it will work also for regular action bar with a few modifications..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload