我尝试了很多答案,但我无法隐藏片段中的操作栏,它始终显示。我不明白为什么,你能帮帮我吗?
这是我的代码: Splash片段:
public class SplashFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getActivity().getActionBar().hide();
View view = inflater.inflate(R.layout.fragment_splash, container, false);
LoginButton authButton = (LoginButton) view.findViewById(R.id.login_button);
authButton.setReadPermissions(Arrays.asList("public_profile","email","user_friends"));
return view;
}
}
我对创建方法的主要活动:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
//getActionBar().hide();
setContentView(R.layout.activity_main);
DebugHTTPRequests.enable();
}
我的风格应用主题:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">@color/mb_green</item>
<item name="android:actionOverflowButtonStyle">@style/OverflowMenuButton</item>
<item name="android:windowBackground">@color/white</item>
<item name="android:actionBarWidgetTheme">@style/PopupMenuTextView</item>
</style>
<style name="MyApp.actionBarWidgetTheme" parent="@style/AppTheme" >
<item name="android:spinnerDropDownItemStyle">@style/MyApp.Widget.DropDownItem.Spinner</item>
</style>
<style name="MyApp.Widget.DropDownItem.Spinner" parent="@android:style/Widget.DropDownItem.Spinner">
<item name="android:textAppearance">@style/MyApp.TextAppearance.Widget.DropDownItem</item>
</style>
<style name="MyApp.TextAppearance.Widget.DropDownItem" parent="@android:style/TextAppearance.Widget.DropDownItem">
<item name="android:textColor">@color/mb_green</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@color/white</item>
<item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/mb_d_green</item>
</style>
<!-- ActionBar tabs text styles -->
<style name="MyActionBarTabText" parent="@android:style/Widget.Holo.ActionBar.TabText">
<item name="android:textColor">@color/mb_green</item>
</style>
<!-- Over flow icon (3 carrés) -->
<style name="OverflowMenuButton" parent="@android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">@drawable/ic_fc_settings</item>
</style>
<!-- Change Overflow Menu ListView Text Size and Text Size -->
<style name="PopupMenuTextView" parent="@style/android:Theme.Holo.Light">
<item name="android:textColor">@color/mb_green</item>
<item name="android:background">@color/transparent</item>
</style>
我不明白为什么getActivity()。getActionBar()。hide()什么都不做。
答案 0 :(得分:3)
尝试requestWindowFeature(Window.FEATURE_NO_TITLE);
修改正如@zgc7009所述,必须在requestWindowFeature()
之前调用setContentView()
答案 1 :(得分:0)
最后我更改了我的应用程序设计,我在主要活动之前创建了一个activty(启动活动),并删除了启动片段。
它适用于requestWindowFeature(Window.FEATURE_NO_TITLE);
谢谢!
答案 2 :(得分:0)
我认为在Fragment中我们必须声明如下:
((AppCompatActivity) getActivity()).getSupportActionBar().show();