我应该在显示DialogFragments时何时使用getFragmentManager(),何时应该使用getSupportFragmentManager()?
目前,我正在显示我的DialogFragments如下:
myDialogFragment.show(getFragmentManager(), "My Dialog Fragment");
Run Code Online (Sandbox Code Playgroud) 所以我使用ActionBarSherlock并决定切换到新的ActionBarCompat.使用ABS,可以使用本文中描述的方式隐藏ActionBar: 如何在创建活动之前隐藏操作栏,然后再次显示它?
但是,随着ActionBarCompat上API14的应用程序崩溃,因为当你设置android:windowActionBar为false的getSupportActionBar()方法返回null,即使你已经宣布getWindow().requestFeature(Window.FEATURE_ACTION_BAR);进入onCreate()方法.
有趣的是,如果你打电话getActionBar(),你得到的对象,一切正常.
那么,这是一个错误还是我错过了什么?欢迎任何想法!
styles.xml 文件:
<style name="Theme.MyApp" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleSize">0dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
MyActivity.java 文件:
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the action bar feature. This feature is disabled by default into the theme
// for specific reasons.
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
...
// By default the action bar is hidden.
getSupportActionBar().hide();
}
Run Code Online (Sandbox Code Playgroud)