动作条与支持库和碎片覆盖内容 [英] ActionBar with support library and Fragments overlay content
问题描述
我添加在 Android的支持库-V7-appcompat 以我的项目从上面API 7级支持动作条。
它的工作原理就像一个魅力的Android 4.0+和还对Android 2.3的一个正常的活动具有的setContentView中的onCreate,但当活动中加载的的onCreate片段中的动作条被重叠我的布局的内容。在所有其他情况下的动作条效果很好。
下面是一些code:
类AssetsActivity扩展ActionBarActivity {
@覆盖
保护无效的onCreate(捆绑为arg0)
{
super.onCreate(为arg0);
OpenLocalFragment资产= OpenLocalFragment.newInstance(指数);
assets.setArguments(getIntent()getExtras());
getSupportFragmentManager()的BeginTransaction()
。新增(android.R.id.content,资产).commit();
}
}
本次活动的主题设定在清单为:
@风格/ Theme.AppCompat
这是这是在Android 2.3的结果(4.0+上的动作条的显示效果)
您可以SE第一lisview项overlaping的动作条(白色圆形图标和标题我的活动)
这是可能的,我发现在支持库中的错误,它被释放只有2天了? 感谢所有。
编辑: 这是现在正式固定的发布在支持库V19
由于JJD下面评论,就可以正常使用 android.R.id.content 是 appcompat-V7 r.19.0.0 或更高版本。 HOME键也正常运行。
使用换句话说:如果你使用19.0.0或更新版本下的解决方法是不再需要。
我得到了答案,在 code.google .COM 。我从弗雷德里克的回答做了一个总结:
有关pre ICS的设备必须使用:
而不是R.id.action_bar_activity_content
android.R.id.content
R.id.action_bar_activity_content 在布局用于显示应用程序内容的新的ID,它会出现,它取代android.R.id.content当您使用支持V7 appcompat ActionBarActivity。
您可以使用此code检索活动内容的正确ID:
公共静态INT getContentViewCompat(){
返回Build.VERSION.SDK_INT> = Build.VERSION_ codeS.ICE_CREAM_SANDWICH?
android.R.id.content:R.id.action_bar_activity_content;
}
由于弗雷德里克·
I added the android-support-library-v7-appcompat to my project to support ActionBar from API level 7 above.
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.
Here is some code:
class AssetsActivity extends ActionBarActivity{
@Override
protected void onCreate(Bundle arg0)
{
super.onCreate(arg0);
OpenLocalFragment assets = OpenLocalFragment.newInstance(index);
assets.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, assets).commit();
}
}
The theme of this activity is set in the manifest to:
@style/Theme.AppCompat
An this is the result on android 2.3 (on 4.0+ the ActionBar shows well)
You can se that the first lisview item is overlaping the ActionBar(White round icon and title "My activity")
It is possible that i found a bug in the support library, it is released only for 2 days now? Thanks to all.
Edit: This is now officially fixed and released in the Support Library v19.
As JJD commented below, you can use normally android.R.id.content with appcompat-v7 r.19.0.0 or newer. The home button works too.
With other words: The workaround below is no more needed if you use version 19.0.0 or newer.
I got the answer at code.google.com. i've made a summary from frederic's answer:
For pre ICS devices you must use:
R.id.action_bar_activity_content
instead of
android.R.id.content
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.
You can use this code to retrieve the correct id of the activity content :
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;
}
Thanks to frederic
这篇关于动作条与支持库和碎片覆盖内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!