LoginSignup
28
25

More than 5 years have passed since last update.

ハンバーガーアイコンの色を変える話

Posted at

ActionBarDrawerToggleがデフォルトで作ってくれるハンバーガーアイコンは黒いのですが、デザイナーさんから色を指定されてしまって、なんとかして色を変えなきゃならなくなりました。

そこで、Google先生に相談したところ、StackOverflowで、これとかこれとかを見つけました。

それによると、ハンバーガーアイコンのスタイルを決めているのは、

<style name="Base.Widget.AppCompat.DrawerArrowToggle" parent="">
    <item name="color">?android:attr/textColorSecondary</item>
    <item name="thickness">2dp</item>
    <item name="barSize">18dp</item>
    <item name="gapBetweenBars">3dp</item>
    <item name="topBottomBarArrowSize">11.31dp</item>
    <item name="middleBarArrowSize">16dp</item>
    <item name="drawableSize">24dp</item>
    <item name="spinBars">true</item>
</style>

こんな感じらしいので、

<style  name="Theme.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="drawerArrowStyle">@style/AppDrawerArrowToggle</item>
</style>

<style name="AppDrawerArrowToggle" parent="Base.Widget.AppCompat.DrawerArrowToggle">
    <item name="color">(アイコンの色)</item>
</style>

といった感じで、変えることができます。わかっちゃえば、簡単ですね。

当然、AndroidManifest.xmlで、applicationのandroid:themeかactivityのandroid:themに、Theme(上の例だと、@style/Theme.AppTheme)を指定する必要があります。

28
25
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
28
25