[英]Action bar is not hiding completely
當我從 tab2 切換到 tab1 或 tab3 時,我想在運行時隱藏我的操作欄,但它留下了空白
我的活動:(帶有 TabLayout 和 3 個片段)
切換到另一個選項卡,操作欄現在隱藏,但有一個空格:
正在使用actionBar.hide
/ actionBar.show
,任何線索如何正確刪除這個額外的空間??? 如果我試圖實現的目標是不可能的,那么請指導我以任何替代方式
代碼:
ActionBar actionBar;
........
........
actionBar = getSupportActionBar();
........
........
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
if (tab == tab2){
actionBar.show();
}else {
actionBar.hide();
}};
添加了 XML 代碼:
MainActivity 包括content_main
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="MainActivity"
android:animateLayoutChanges="true">
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
內容主:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/main_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:animateLayoutChanges="true">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e4e4e4"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fillViewport="false"
android:clickable="false" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/tabs"/>
</RelativeLayout>
試試這個@你想隱藏/顯示ActionBar的地方,
requestWindowFeature(Window.FEATURE_ACTION_BAR);
// delaying the hiding of the ActionBar
Handler h = new Handler();
h.post(new Runnable() {
@Override
public void run() {
getActionBar().hide();//OR
//getActionBar().show();
}
});
如果活動
getSupportActionBar().hide();
or
getActionBar().hide();
如果片段
getActivity().getSupportActionBar().hide();
or
getActivity().getActionbar().hide();
試試這個
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
在我的片段中,這就是我隱藏ActionBar
,它運行良好
// MainActivity is the activity which contains fragment
ActionBar actionBar = ((MainActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
xml
<style name="AppTheme.myNoActionBarTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
然后在 manifest.xml
<activity android:name=".NoticeboardActivity" android:theme="@style/AppTheme.myNoActionBarTheme"></activity>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.