因为 ActionBar是系统的 我们想与用户交互比较麻烦 ,但我们可以以通过 // getSupportActionBar().hide(); 把 系统的ActionBar 隐藏掉。
使用Toobar替换 Actionbar 的话 我们可以把toobar放在rootview 的第一个位置 当rootview的第一个子view
布局中是这样:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:tl="http://schemas.android.com/apk/res-auto"
android:background="#DECE58"
android:layout_height="match_parent"
tools:context="ry.com.hxf.ui.main.activity.SplashActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
tl:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/colorPrimaryDark"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"></android.support.v7.widget.Toolbar>
<FrameLayout
android:layout_below="@+id/toolbar"
android:id="@+id/fl_body"
android:layout_width="match_parent"
android:layout_above="@+id/tablayout_tl"
android:layout_height="match_parent"></FrameLayout>
<com.flyco.tablayout.CommonTabLayout
android:id="@+id/tablayout_tl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
tl:tl_indicator_height="0dp"
android:background="@color/white"
tl:tl_iconHeight="20dp"
tl:tl_iconWidth="20dp"
tl:tl_indicator_color="@color/gray"
tl:tl_textSelectColor="@color/main_color"
tl:tl_textUnselectColor="@color/light_gray"
tl:tl_textsize="11sp"
tl:tl_underline_height="0dp"
>
</com.flyco.tablayout.CommonTabLayout>
</RelativeLayout>
android:layout_height="?actionBarSize"
这里 toobar的高度默认使用 actionbar的高度
代码中 把 actionbar 替换成 toobar
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setSupportActionBar(toolbar); 把actionbar 添加成了toobar
同时项目style 也要改成 noactionbar的样式 :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>