在低版本Android中fragment会overlay ActionBar区域

来源:互联网 发布:mac 转码软件 编辑:程序博客网 时间:2024/04/29 13:13

1 问题

It works like a charm on android 4.0+ and also on android 2.3 with a normal Activity that has setContentView in onCreate, but when the activity is loading an Fragment in onCreate the ActionBar gets overlapped with the content of my layout. At all other scenarios the ActionBar works well.
2 解释

R.id.action_bar_activity_content is a new id used in layout for displaying app content, it would appear that it replace android.R.id.content when you use support v7 appcompat ActionBarActivity.
3 解决方案

  public static int getContentViewCompat() {        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?                android.R.id.content : android.support.v7.appcompat.R.id.action_bar_activity_content;    }

感谢大神:

https://code.google.com/p/android/issues/detail?id=58108

0 0
原创粉丝点击