1.
android toolbar 假标题居中
<android.support.v7.widget.Toolbar android:id="@+id/toolbar_top" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Toolbar Title" android:layout_gravity="center" android:id="@+id/toolbar_title" /> </android.support.v7.widget.Toolbar>
This means that you can style the TextView however you would like because it’s just a regular TextView. So in your activity you can access the title like so:
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);
- 1
- 2
If anyone else can’t remove the default app name title, do this:
1、Call setSupportActionBar(yourToolbar)
2、Call
getSupportActionBar().setDisplayShowTitleEnabled(false);`
2.
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”xmlns:
tools=”http://schemas.android.com/tools”android:layout_width=”match_parent”android:layout_height=”match_parent” >
<android.support.v7.widget.Toolbar android:id=”@+id/toolbar”android:layout_width=”match_parent”android:layout_height=”wrap_content”
android:background=”#0066ff”android:minHeight=”?attr/actionBarSize” >
<TextViewandroid:layout_width=”wrap_content”android:layout_height=”wrap_content”android:layout_centerInParent=”true”
android:layout_gravity=”center”android:text=”www.dastorm.com”android:textColor=”@android:color/white”android:textSize=”20sp”
android:textStyle=”bold” />
</android.support.v7.widget.Toolbar>
</RelativeLayout>
3.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" > <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#0066ff" android:minHeight="?attr/actionBarSize" > </android.support.v7.widget.Toolbar> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_gravity="center" android:text="text" android:textColor="@android:color/white" android:textSize="20sp" android:textStyle="bold" /> </RelativeLayout>
mToolbar= (Toolbar) findViewById(R.id.toolbar); mToolbar.setTitle(""); setSupportActionBar(mToolbar);注意act继承AppCompatActivity