您的位置:首页 > 移动开发 > Android开发

Android自学之路,ToolBar的使用标题居中颜色设置

2015-12-03 19:56 393 查看
要使用,toolbar就必须将主题设置为没有ActionBar在style文件中将Theme设置为NoAcTIONBAR

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
然后再Java中写入
` android.support.v7.widget.Toolbar mToolBar= (android.support.v7.widget.Toolbar) this.findViewById(R.id.toolbar);
setSupportActionBar(mToolBar);`

设置total的颜色的方法是,在style中新建项

<style name="ToolBarTheme">
<item name="android:textColorPrimary">@color/white</item>
</style>


设置主副标题在Java中设置

mToolBar.setTitle(“My Title”);

mToolBar.setSubtitle(“Sub title”);

标题居中设置:

将标题设为“”

然后在layout中
<TextView

android: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"></TextView>

</android.support.v7.widget.Toolbar>


好的今天的博客先写到这里,打球去了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: