ToolBar居中显示文字或控件

来源:互联网 发布:网络本科有哪些学校 编辑:程序博客网 时间:2024/06/08 17:17

转载请标明出处:http://blog.csdn.net/wu_wxc/article/details/48263007
本文出自【吴孝城的CSDN博客】

想在ToolBar工具栏居中显示文字或控件其实并不难,只需要在toolbar布局里加入就行



在toolbar里,创建LinearLayout布局,设置宽度匹配父元素,内部控件居中显示,然后就可以在LinearLaout里写控件了。


<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_height="wrap_content"    android:layout_width="match_parent"    android:background="?attr/colorPrimary">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:gravity="center"        android:orientation="horizontal">        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="按钮"            android:textSize="20sp"/>        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="你好"            android:textSize="20sp"/>    </LinearLayout></android.support.v7.widget.Toolbar>

至于ToolBar其他内容看

aterial Design 之 ToolBar 


源码


1 0
原创粉丝点击