我创建了一个Toolbar
并将其添加到我的 main_activity.xml 中,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_detail"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/loginBrown"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#fff"
android:textSize="16sp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigation"
android:animateLayoutChanges="true">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
app:itemIconTint="@color/nav_item_state_list"
app:itemTextColor="@color/nav_item_state_list"
app:menu="@menu/bottom_navigation_items" />
</RelativeLayout>
也改为style.xml
:<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
在MainActivity
我添加了这个:
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar_detail);
setSupportActionBar(toolbar);
但即使这样也没有显示在第一个 Fragment
我做了一个fragment.replace()
展示第一个Fragment
,我不知道那是不是错误的事情
加载片段的 FrameLayout 位于 ToolBar 的顶部。这就是为什么你看不到它。添加android:layout_marginTop="?android:attr/actionBarSize"
到框架布局。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句