This post is to explain how you can change the Default Color of Android App's or a particular Activity,
This can be done both using Style XML code and Programmatically using Java or Kotlin Code.
Example 1: Change Android Activity Title Bar Color using Style XML
- Open your activity_ .xml file under /res/layouts
- Click on Code
- Look for androidx.appcompat.widget.Toolbar
- Now look for attribute android:background=
- Now change its value to any hex color code you want example: #eeeeee (its better you add this to colors.xml and use reference instead example: @color/gray
- Run your App on the emulator or device you should see that the Titlebar/Toolbar color has changed.
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/gray"
app:popupTheme="@style/AppTheme.PopupOverlay" />
Code Snippet: colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
<color name="gray">#eee</color>
</resources>
Example 2: Programatically using Java/Kotlin Code:
Add the below code in your Activity java class in onCreate() method,
ActionBar aBar;
aBar= getSupportActionBar();
ColorDrawable cd = new ColorDrawable(Color.parseColor("#eee"));
actionBar.setBackgroundDrawable(cd);
More Posts related to Android,
- Increase Android Emulator Timeout time
- Android : Remove ListView Separator/divider programmatically or using xml property
- Error : Invalid key hash.The key hash does not match any stored key hashes
- How to Change Android Toast Position?
- Android Alert Dialog with Checkboxes example
- Android : No Launcher activity found! Error
- Android Development: Spinners with Example
- Failed to sync Gradle project Error:failed to find target android-23
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Disable Fading Edges Scroll Effect Android Views
- How to create Toast messages in Android?
- Channel 50 SMSes received every few minutes Android Phones
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Create Custom Android AlertDialog
- How To Disable Landscape Mode in Android Application
- Android Development - How to switch between two Activities
- incorrect line ending: found carriage return (\r) without corresponding newline (\n)
- Generate Facebook Android SDK keyhash using java code
- Android Error Generating Final Archive - Debug Certificate Expired
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Android RatingBar Example
- 11 Weeks of Android Online Sessions-15-Jun-to-28-Aug-2020
- Download interrupted: Unknown Host dl-ssl.google.com Error Android SDK Manager
- fill_parent vs match_parent vs wrap_content
- Android : Connection with adb was interrupted 0 attempts have been made to reconnect
More Posts:
- PowerShell ISE Alternative for Mac - Powershell
- TL;DR List of 34+ New Features added to iOS 17 for iPhones - iOS
- How to find Integer MAX and MIN Value in Java - Java
- [fix] Deprecated gradle features were used in this build, making it incompatible with Gradle X.0 - Gradle
- Online Regex Tester Tool - Tools
- How to highlight the current line in Notepad++ - NotepadPlusPlus
- Notepad++ Editor alternatives for macOS - NotepadPlusPlus
- Read file from Windows CMD (Command Line) - Windows