Last active
October 29, 2018 15:29
-
-
Save ShinichiroFunatsu/51f2043bf4ee6e3125682b3696c26320 to your computer and use it in GitHub Desktop.
[Android] How To Change "ActionBar" Title Text Color when applied "Theme.MaterialComponents.Light.DarkActionBar" to AppTheme ref: https://qiita.com/ShinichiroFunatsu/items/938e07d44b032fad7318
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-android-extensions' | |
android { | |
compileSdkVersion 28 | |
defaultConfig { | |
applicationId "com.example.actionbartextcolor" | |
minSdkVersion 26 | |
targetSdkVersion 28 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |
} | |
} | |
} | |
dependencies { | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
implementation 'com.android.support:appcompat-v7:28.0.0' | |
implementation 'com.android.support:design:28.0.0' | |
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<!-- Base application theme. --> | |
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar"> | |
<!-- Customize your theme here. --> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
<item name="actionBarStyle">@style/MyActionBar</item> | |
</style> | |
<!-- this cannot apply textColor --> | |
<style name="MyActionBar" | |
parent="@style/Widget.AppCompat.ActionBar"> | |
<item name="android:titleTextStyle">@style/TitleTextStyle</item> | |
<item name="android:background">@color/colorPrimary</item> | |
<item name="android:backgroundStacked">@color/colorPrimary</item> | |
<item name="android:backgroundSplit">@color/colorPrimary</item> | |
<!-- Support library compatibility --> | |
<item name="titleTextStyle">@style/TitleTextStyle</item> | |
<item name="background">@color/colorPrimary</item> | |
<item name="backgroundStacked">@color/colorPrimary</item> | |
<item name="backgroundSplit">@color/colorPrimary</item> | |
</style> | |
<style name="TitleTextStyle" | |
parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> | |
<item name="android:textColor">@color/colorAccent</item> | |
</style> | |
</resources> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<!-- Base application theme. --> | |
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar"> | |
<!-- Customize your theme here. --> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
<item name="toolbarStyle">@style/CustomToolBarStyle</item> | |
</style> | |
<!-- ActionBar is no longer Toolbar --> | |
<style name="CustomToolBarStyle" parent="@style/Widget.AppCompat.Toolbar"> | |
<item name="titleTextColor">@color/colorAccent</item> | |
</style> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (a.hasValue(styleable.Toolbar_titleTextColor)) { | |
this.setTitleTextColor(a.getColor(styleable.Toolbar_titleTextColor, -1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment