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

要使用,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>

好的今天的博客先写到这里,打球去了。

你可能感兴趣的:(android,UI)