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,
- Change Android Toast background color
- Maven : java.lang.ClassNotFoundException: Xmx512m
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Android Alert Dialog with Checkboxes example
- Android Error Generating Final Archive - Debug Certificate Expired
- How to add Newline to text in Android TextView
- Read Text file from SD Card : Android Programming
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- ActivityManager Warning: Activity not started, its current task has been brought to the front
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Android Developers Bluetooth Tutorial
- java.lang.ClassNotFoundException android.support.v7.widget.Toolbar [Fix]
- Android: Save Data in local Db using Android Room
- Channel 50 SMSes received every few minutes Android Phones
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Changing Android Intent Tittle using java code
- Android : No Launcher activity found! Error
- How to change TextView or EditText Text Color on Focus and on Press
- How to display Toast on Button Click : Android
- Android : Execute some code after back button is pressed
- Stop android adb service from command prompt or terminal
- [Soluiton] You already have the latest version of Android Studio installed
- Create Custom Android AlertDialog
- Android R Cannot Be Resolved To A Variable
- How to make Android EditText not editable
More Posts:
- How to stop/start/restart apache server using command [Ubuntu] - Ubuntu
- Fix java.net.ProtocolException: Invalid HTTP method - Java
- JSON Nest Objects Example: JSON Tutorial - Json-Tutorial
- Install specific JRE on Ubuntu using apt - Ubuntu
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end users experience - Java
- list of jars required for hibernate 4.x.x - Java
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted. - Android
- Your Android SDK is out of date or is missing templates. Please ensure you are using SDK version 22 or later. - Android