LoginSignup
16
17

More than 5 years have passed since last update.

Toolbarのテキスト色をstyleで指定する

Posted at

基本的な指定の仕方はこちら。
ToolBarの背景色やオプションメニューの色を変更する方法

themeの指定とは違うテキスト色をToolbarに指定したい時、単純にtextColorをセットするだけでは反映されません。これは、themeの指定で上書きされてしまうからです。

Toolbarにテキスト色をstyleで指定する場合は、themeとなるstyleを定義してそれをセットする必要があります。

styles.xml
<style name="BaseToolbar" parent="@style/Widget.AppCompat.Toolbar">
    <item name="android:theme">@style/ToolbarTheme</item>
</style>

<style name="ToolbarTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:textColorPrimary">@color/toolbar_text</item>
    <item name="android:textColorSecondary">@color/toolbar_text</item>
</style>
layouts/activity_main.xml
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    style="@style/BaseToolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

以上です。

16
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
17