第一种:
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="50dp" android:background="@color/color_52a3ff" app:layout_scrollFlags="scroll|enterAlways" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> <TextView android:id="@+id/id_tv_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="知乎" android:textColor="@android:color/white" android:textSize="20sp" /> </RelativeLayout>然后将Toolbar的title设置成 toolbar.setText(""); 就可以了
第二种:
Activity中的代码很简单,Activity继承android.support.v7.app.ActionBarActivity类。把Toolbar的title设置为空,并把Toolbar 设置到ActionBar上就行了:
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setTitle(“”);
setSupportActionBar(mToolbar);