我用ToolBar替换了Activity中的ActionBar。但是当活动加载时,它会在一秒钟内显示并消失。我的活动布局如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/relativeLayout"
android:layout_below="@+id/header" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/white"
android:id="@+id/relativeLayout">
<TextView
android:id="@+id/tv_driver_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ALLIE"
android:paddingTop="8dp"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView
android:id="@+id/tv_driver_vehicle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_driver_name"
android:paddingBottom="@dimen/activity_horizontal_margin"
android:text="NISSAN 389 - VQX"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_star"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:id="@+id/imageView"
android:layout_alignTop="@+id/tv_driver_vehicle"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4.75"
android:textSize="20sp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/imageView"
android:layout_toStartOf="@+id/imageView"
android:gravity="center"
android:id="@+id/textView" />
</RelativeLayout>
</RelativeLayout>
我添加了一个自定义视图,该视图在操作栏之前正常工作,如下所示:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowCustomEnabled(true);
View v = getLayoutInflater().inflate(R.layout.custom_actionbar_maps, null);
toolbar.addView(v);
当活动加载并且地图放大到当前位置时,工具栏会消失。
答案 0 :(得分:1)
您设置的片段位于@+id/header
下方,但工具栏的标识为toolbar
。改变其中一个,这两个都是相同的
您的片段正在填充您的活动,因此首先您可以看到您的工具栏,但是一旦片段被加载,它就在工具栏上。