您的位置:首页 > 其它

Toolbar修改字体颜色与添加返回键

2017-08-28 15:47 218 查看
1.布局中添加toolbar:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:titleTextColor="?attr/colorPrimary"
app:title="Toolbar"
app:titleTextColor="#ffffff"
app:theme="@style/ToolbarTheme"//通过主题改变返回键颜色
android:minHeight="?attr/actionBarSize">

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


ToolbarTheme:

<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<item name="colorControlNormal">#ffffff</item>
</style>


2.代码中设置显示返回键:

setSupportActionBar(mToolbar);
//设置是否有返回箭头
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//设置标题文字
mToolbar.setTitle("mToolbar");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: