Android ToolBar小记
2019-01-30 本文已影响0人
编程的猫
通常我在页面的头部都想需要使用到ToolBar,往往在toolbar中设置字体不会居中,当然也可以通过修改属性设置title居中,这里介绍另外一种方法,关于ToolBar的使用,后续会补充
- 我简单设置了下toolBar的属性,如下
<!--Toolbar的样式属性-->
<style name="toolBar_theme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<item name="colorControlNormal">@color/white</item>
<item name="android:actionBarSize">48dp</item>
</style>
- 我的toolBar的布局文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blue">
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:theme="@style/toolBar_theme"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
</android.support.v7.widget.Toolbar>
<TextView
android:id="@+id/toolBarTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="text"
android:textColor="@color/white"
android:textSize="17sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
-
示例图
image.png
ToolBar待续。。。