Loading up the hierarchyviewer
in the Android SDK's tools directory, it appears that the view you place fragments in is android.R.id.content
on 4.x devices and is R.id.action_bar_activity_content
on 2.3 devices running the AppCompat ActionBar library.
Unfortunately it seems that you might need to branch based off platform versions when adding fragments. This is suggested in http://code.google.com/p/android/issues/detail?id=58108 (not sure about 3.x devices yet).
Use this method to get the proper view for adding Fragment
's. My testing also shows that 3.x devices act similar to 2.3 devices when using the AppCompat ActionBar library.
public static int getContentViewCompat() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH ?
android.R.id.content : R.id.action_bar_activity_content;
}
hierarchyviewer screenshots
- 2.3
- 4.x