0
0

More than 3 years have passed since last update.

【Android】ActionBarでハマったこと

Posted at

importが違った

ActionBar bar = getSupportActionBar();
で、赤い波線が出てエラーが出てしまっていた。
警告を読めばわかることだが、原因はimportしているActionBarが違っていたでした。

  • NG
import android.app.ActionBar;
  • OK
import androidx.appcompat.app.ActionBar;

ActionBarの文字の色を変更する方法


<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="actionBarStyle">@style/CustomActionBar</item>
</style>

<style name="CustomActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="titleTextStyle">@style/CustomActionBarTitleStyle</item>

</style>

<style name="CustomActionBarTitleStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="backgroundColor">@color/teal_700</item>
    <item name="android:textColor">@color/teal_200</item>
</style>

でも、まだハマっています…

しかし、上記のやり方では、Themeが
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> の場合だと、文字の色は変わらなかった。

Themeは変えたくない場合、どうすれば良いのだろう。
styleでがんばる方法がなかったら、ActionBar.setCustomView()するのでしょうか?

0
0
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
0
0